--//----------------------------------------------------------//--
--//
--//  * A/D Aspect RELOADED 1.0.6 
--//  * Copyright 2011-2012
--//  * by Mateusz 'Mate_' Daszuta
--//  * rhbk91@gmail.com
--//
--//----------------------------------------------------------//--

screenWidth, screenHeight = guiGetScreenSize()
local k_system  = {ping={},fps={},ploss={},packet={0,0},tc = getTickCount()}
_game_status = 0
	local replace_m = {}
local g_p_loss = '0.00%'
selector_data = {1294, -809,88.3 ,	51, 		0}
MTAwin = true
round_mode = {'normal',0}
local FPSLimit = 46
Local = localPlayer
local v_p_t_sec 
function math.round(number, decimals, method)
    decimals = decimals or 0
    local factor = 10 ^ decimals
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
    else return tonumber(("%."..decimals.."f"):format(number)) end
end
local mnoznik = screenWidth/100
mnoznik = math.round(mnoznik, 0)
local size1 = math.round(0.15*mnoznik, 2)
if size1 < 1 then
size1 = 1
end 
function math.format(number)
return tonumber(string.format("%.4f", number))
end--,lblue=tocolor(77,152,205,255)
colors_g = {gold=tocolor(238,180,34,255),gray=tocolor(200,200,200,255),dgreen=tocolor(34,139,34,255),green=tocolor(100,180,34,255),black=tocolor(0,0,0,255),black2=tocolor(20,20,20,255),black3=tocolor(35,35,35,255),lblue=tocolor(77,152,205,255),lgray=tocolor(162,170,175,255),red=tocolor(225,25,25,255),white=tocolor(225,225,225,255)}
local g_open_s ={team=false}

function callClient(funcname, ...)
    local arg = { ... }
    if (arg[1]) then
        for key, value in next, arg do arg[key] = tonumber(value) or value end
    end
    loadstring("return "..funcname)()(unpack(arg))
end
addEvent("on_client_call", true)
addEventHandler("on_client_call", root, callClient)

function callServer(funcname, ...)
    local arg = { ... }
    if (arg[1]) then
        for key, value in next, arg do
            if (type(value) == "number") then arg[key] = tostring(value) end
        end
    end
    triggerServerEvent("on_server_call", root, funcname, unpack(arg))
end

function yhy2(h,s)
local mn = s/h
return tonumber(string.format("%.1f", screenHeight*mn))
end
function returnSizeFromResolution(h,s)
local mn = s/h
return tonumber(string.format("%.1f", (screenWidth+screenHeight/2)*mn))
end

--[[
function FormatTimer(m,s)
	if string.len(s) == 1 then 
		s = "0"..s
	end 
	if string.len(m) == 1 then
		m = "0"..m
	end
	return m..":"..s
end]]

function FormatTimer(m,s)
	if s < 10 then 
		s = "0"..s
	end 
	if m < 10 then
		m = "0"..m
	end
	return m..":"..s
end

function PobierzPozycjeKamery( x,y,z,obrot ,dystans )	
    obrot = obrot/180*3.14159265358979
    x = x - ( math.sin(obrot) * dystans )
    y = y + ( math.cos(obrot) * dystans )
	return x, y, z
end


alphat = 255

function r_fadeanimation()
	local tc = getTickCount()
	dxDrawImage( 0, 0,  screenWidth, screenHeight, myScreenSource2,0,0,0,tocolor(255,255,255,alphat) )
	alphat = 255 - (  tc -f_anim.start)*f_anim.add
	
		if tc > f_anim.end_ then
		removeEventHandler( "onClientRender", root,r_fadeanimation )
		destroyElement( myScreenSource2 )
		end
end


	function sdasddsadsa(time)
		if not isElement( myScreenSource2 ) then
			time = time or 1000
			f_anim = {start=getTickCount(),end_=getTickCount()+time,add=255/time}
			myScreenSource2 = dxCreateScreenSource (  screenWidth, screenHeight )          -- Create a screen source texture which is 640 x 480 pixels
			dxUpdateScreenSource( myScreenSource2 ,true) 
			alphat = 255
			addEventHandler( "onClientRender", root,r_fadeanimation )
		end	
	end


function DxDrawTimeText(times,x,y,scale,font,outlinesize, outlinecolor,postGUI,...)
local function on_Client_Render_bs_23()
	if MTAwin then
dxDrawColorText(x,y,scale,font,outlinesize, outlinecolor,postGUI,unpack(arg))
	end
end
addEventHandler("onClientRender", getRootElement(),on_Client_Render_bs_23)
setTimer(function() removeEventHandler("onClientRender", getRootElement(),on_Client_Render_bs_23) end,times,1)
end

function dxDrawTextAlongTime(fps,x,y,scale,font,...)
	local render = 0
	local function draw_t()
		if MTAwin then
			dxDrawTexts_s(x,y,scale,font,unpack(arg))
			render = render +1
				if render == fps then
					removeEventHandler("onClientRender", getRootElement(),draw_t)
				end
		end		
	end
addEventHandler("onClientRender", getRootElement(),draw_t)
end

function drawBorderText(text, x, y, color, scale, font, outlinesize, outlinecolor,postGUI)
	local alpha = math.floor(color / 16777216)
	outlinesize = outlinesize or 2
	if outlinesize > 0 then
		for offsetX=-outlinesize,outlinesize,outlinesize do
			for offsetY=-outlinesize,outlinesize,outlinesize do
				if not (offsetX == 0 and offsetY == 0) then
					dxDrawText(text, x + offsetX, y + offsetY, x + offsetX, y + offsetY, outlinecolor or tocolor(0, 0, 0, alpha), scale, font,"left", "top", false, false, postGUI )
				end
			end
		end
	end
	dxDrawText(text, x, y, x, y, color, scale, font,"left", "top", false, false, postGUI)
end
function drawCarText(text, x, y, color, scale, font)
dxDrawText ( text, x, y ,x, y, color, scale, font )
end
function drawShadowText(text, x, y, color, scale, font, shadowDist,postGUI, width, align)
	shadowDist = shadowDist or 1
	
	dxDrawText(text, x + shadowDist, y + shadowDist, x + shadowDist + (width or 0), 0, tocolor(0, 0, 0, 255), scale or 1, font or 'default', width and (align or 'center') or 'left',"top", false, false, postGUI )
	dxDrawText(text, x, y, x + (width or 0), 0, color, scale, font, width and (align or 'center') or 'left',"top", false, false, postGUI )
end


function dxDrawColorText(x,y,scale,font,outlinesize, outlinecolor,postGUI,...)
	local tableint = #arg/2
	local newX = x
		for i=1, tableint do
		local ther = dxGetTextWidth ( arg[i], scale,font )
		--dxDrawText(arg[i], newX+1, y+1, 0, 0, colors_g.black,  scale, font, "left" ,"top", false, false, postGUI )
		dxDrawText(arg[i], newX, y, 0, 0, arg[i+tableint],  scale, font, "left" ,"top", false, false, postGUI )
		newX = newX + ( ther or 0 )
		end
		local asd = newX - x 
		return asd
end

function dxDrawTexts(x,y,scale,font,...)
	local newX = x
		for i=1,#arg,2 do
			local ther = dxGetTextWidth ( arg[i], scale,font )
			dxDrawText(arg[i], newX, y, 0, 0, arg[i+1],  scale, font)
			newX = newX + ther 
		end
end

function dxDrawTexts_s(x,y,scale,font,...) --//shadow
	local newX = x
		for i=1,#arg,2 do
			local ther = dxGetTextWidth ( arg[i], scale,font )
			dxDrawText(arg[i], newX+1, y+1, 0, 0, colors_g.black,  scale, font)
			dxDrawText(arg[i], newX, y, 0, 0, arg[i+1],  scale, font)
			newX = newX + ther 
		end
end

function dxDrawBoardText(x,y,scale,font,text,color)



			dxDrawText(text, x+2, y, 0, 0, colors_g.black,  scale, font)
			dxDrawText(text, x-2, y, 0, 0,  colors_g.black,  scale, font)
			dxDrawText(text, x, y+2, 0, 0, colors_g.black,  scale, font)
			dxDrawText(text, x, y-2, 0, 0,  colors_g.black,  scale, font)	
			dxDrawText(text, x, y, 0, 0, color,  scale, font)

		
end

function dxDrawBoardTextB(x,y,scale,font,text,color)


			dxDrawText(text, x+1, y+1, 0, 0, colors_g.black,  scale, font, "left", "top",false, false, true)
			dxDrawText(text, x-1, y-1, 0, 0,  colors_g.black,  scale, font, "left", "top",false, false, true)
			

			
			dxDrawText(text, x+1, y, 0, 0, colors_g.black,  scale, font, "left", "top",false, false, true)
			dxDrawText(text, x-1, y, 0, 0,  colors_g.black,  scale, font, "left", "top",false, false, true)
			dxDrawText(text, x, y+1, 0, 0, colors_g.black,  scale, font, "left", "top",false, false, true)
			dxDrawText(text, x, y-1, 0, 0,  colors_g.black,  scale, font, "left", "top",false, false, true)	
			
			dxDrawText(text, x, y, 0, 0, color,  scale, font, "left", "top",false, false, true)

		
end

function dxDrawTexts_gui(x,y,scale,font,...)
	local newX = x
		for i=1,#arg,2 do
			local ther = dxGetTextWidth ( arg[i], scale,font )
			dxDrawText(arg[i], newX, y, 0, 0, arg[i+1],  scale, font, "left", "top",false, false, true)
			newX = newX + ther 
		end
end

function dxDrawTexts_guiB(x,y,scale,font,...)
	local newX = x
		for i=1,#arg,2 do
			local ther = dxGetTextWidth ( arg[i], scale,font )
		--	dxDrawText(arg[i], newX, y, 0, 0, arg[i+1],  scale, font, "left", "top",false, false, true)
			dxDrawBoardTextB(newX, y,scale,font,arg[i],arg[i+1])
			newX = newX + ther 
		end
end

function dxDrawTextB ( text, l, t ,r, c, color, scale, font, alignX, alignY, clip, ordBreak,  postGUI )
	for i=1,5 do
		dxDrawText ( text, l+i, t+i ,r, c, colors_g.black2, scale, font, alignX, alignY, clip, ordBreak,  postGUI )
	end
	--dxDrawBoardText( l, t,scale,font,text,color)
	dxDrawText ( text, l, t ,r, c, color, scale, font, alignX, alignY, clip, ordBreak,  postGUI )
end

function dxDrawTextBa ( text, l, t ,r, c, color, scale, font, alignX, alignY, clip, ordBreak,  postGUI )
	dxDrawBoardText( l, t,scale,font,text,color)
	dxDrawText ( text, l, t ,r, c, color, scale, font, alignX, alignY, clip, ordBreak,  postGUI )
end
	
function dxDrawTextBaQ ( text, l, t ,r, c, color, scale, font, alignX, alignY, clip, ordBreak,  postGUI )


			dxDrawText(text, l+2, t, 0, 0, colors_g.black,  scale, font)
			dxDrawText(text, l-2, t, 0, 0,  colors_g.black,  scale, font)
			dxDrawText(text, l, t+2, 0, 0, colors_g.black,  scale, font)
			dxDrawText(text, l, t-2, 0, 0,  colors_g.black,  scale, font)	
			
			dxDrawText(text, l-1, t+1, 0, 0, colors_g.black,  scale, font)
				
			dxDrawText(text, l+1, t+1, 0, 0, colors_g.black,  scale, font)
			
				
			dxDrawText(text, l-1, t-1, 0, 0, colors_g.black,  scale, font)
			dxDrawText(text, l+1, t-1, 0, 0, colors_g.black,  scale, font)
			
	dxDrawText ( text, l, t ,r, c, color, scale, font, alignX, alignY, clip, ordBreak,  postGUI )
end


function dxDrawTextBaQ_c ( text, l, t ,r, c, color, scale, font, color2 )


			dxDrawText(text, l+2, t, 0, 0, color2,  scale, font)
			dxDrawText(text, l-2, t, 0, 0,  color2,  scale, font)
			dxDrawText(text, l, t+2, 0, 0, color2,  scale, font)
			dxDrawText(text, l, t-2, 0, 0,  color2,  scale, font)	
			
			dxDrawText(text, l-1, t+1, 0, 0, color2,  scale, font)
				
			dxDrawText(text, l+1, t+1, 0, 0, color2,  scale, font)
			
				
			dxDrawText(text, l-1, t-1, 0, 0, color2,  scale, font)
			dxDrawText(text, l+1, t-1, 0, 0, color2,  scale, font)
			
	dxDrawText ( text, l, t ,r, c, color, scale,font )
end


function dxDrawText_sh ( text, l, t ,r, c, color, scale, font, color2 )


			
	dxDrawText ( text, l+(scale*2), t+(scale*2) ,r, c, color2, scale,font )
	dxDrawText ( text, l, t ,r, c, color, scale,font )
end

function dxDrawTextBaQ2 ( text, l, t ,r, c, color, scale, font, alignX, alignY, clip, ordBreak,  postGUI )


			dxDrawText(text, l+2, t, 0, 0, colors_g.black,  scale, font)
			dxDrawText(text, l-2, t, 0, 0,  colors_g.black,scale, font, alignX, alignY, clip, ordBreak,  postGUI )
			dxDrawText(text, l, t+2, 0, 0, colors_g.black,scale, font, alignX, alignY, clip, ordBreak,  postGUI )
			dxDrawText(text, l, t-2, 0, 0,  colors_g.black,scale, font, alignX, alignY, clip, ordBreak,  postGUI )	
			
			dxDrawText(text, l-1, t+1, 0, 0, colors_g.black,scale, font, alignX, alignY, clip, ordBreak,  postGUI )
				
			dxDrawText(text, l+1, t+1, 0, 0, colors_g.black,scale, font, alignX, alignY, clip, ordBreak,  postGUI )
			
				
			dxDrawText(text, l-1, t-1, 0, 0, colors_g.black,scale, font, alignX, alignY, clip, ordBreak,  postGUI )
			dxDrawText(text, l+1, t-1, 0, 0, colors_g.black,scale, font, alignX, alignY, clip, ordBreak,  postGUI )
			
	dxDrawText ( text, l, t ,r, c, color, scale, font, alignX, alignY, clip, ordBreak,  postGUI )
end	
function getTeamByType(t_type)
local ar = false
local teams = getElementsByType("team")
	for k,v in ipairs(teams) do
		if getElementData(v,"t_type") == t_type then
		ar = v
		end
	end
	return ar
end	

function getReverseRotation(rot)
local rot2
if rot > 270 then
rot2 = 90 + (rot-270)
elseif rot > 180 then
rot2 = 0 + (rot-180)
elseif rot > 90 then
rot2 = 270 + (rot-90)
else
rot2 = 180 + rot
end
return rot2
end

ActualySpectMode = { team = "Select Team", player = "Select Player", camera = "Camera Type"}
local SpectateMode = {
["Speactator"] = {
	free = true,
	team = true,
	allow_teams = "all"},
["Own_team"] = {
	free = false,
	team = true,
	allow_teams = "own"},	
	}
function GetSpectateMode(type,mode)
	return SpectateMode[type][mode]
end	
function SetSpectateMode(type,mode,value)
	if SpectateMode[type][mode] ~= nil then
		SpectateMode[type][mode] = value
		return true
	else
		return false
	end
end	

function ClientExplosionFunction(x,y,z,theType)
	if theType == 7 or theType == 2 then
	 --outputChatBox("ClientExplosionFunction")
		cancelEvent()
		if theType == 2 then
			createExplosion ( x,y,z+1.5, 12 , false, 0.01, false )
		else
			createExplosion ( x,y,z-1, 7 , true, 1.0, false )
			
		end
	end
end
addEventHandler("onClientExplosion",getRootElement(),ClientExplosionFunction)


	function bm_OnClientDmg()
	cancelEvent()
	end

function getSizeFromResolution2(x)
local s1,s2 = 0,0
	if x > 1279 then
	s1 = 1.4 s2 = 1.0
	elseif x > 1023 then
	s1 = 1.2 s2 = 1.0
	elseif x > 799 then
	s1 = 1.0 s2 = 1.0
	else
	s1 = 0.85 s2 = 1.0
	end
	return s1,s2
end


function getSizeFromResolution(x)
local s1,s2 = 0,0
	if x > 1279 then
	s1 = 1.65 s2 = 1.0
	elseif x > 1023 then
	s1 = 1.3 s2 = 1.0
	elseif x > 799 then
	s1 = 1.0 s2 = 1.0
	else
	s1 = 0.85 s2 = 1.0
	end
	return s1,s2
end

function getSpectateType(team)
local type_l = "Own_team"
	if getTeamName(team) == "Spectator" then
	type_l = "Speactator"
	end
return 	type_l
end	
--[[	
function getScreenPositionByRelative(x,y)
	local nX,nY =x*screenWidth,y*screenHeight 
	return nX,nY
end]]


function getScreenPositionByRelative(x,y)
	local nX,nY =x*screenWidth,y*screenHeight 
	return math.format(nX),math.format(nY)
end

function getScreenPositionByRelativeViaElement(x,y,element)
	local xE,yE = guiGetSize(element,false)
		local xsE,ysE = guiGetPosition(element,false)
		local nX,nY =x*xE,y*yE
	return math.format(nX+xsE),math.format(nY+ysE)
end

function getRelativeByScreenPosition(x,y)
	local nX,nY =x/screenWidth,y/screenHeight 
	return nX,nY
end
function getRelativeByScreenPositionViaElement(x,y,element)
	local xE,yE = guiGetSize(element,false)
	local nX,nY =x/xE,y/yE
	return nX,nY
end

function returnTeamListWithKillsDeaths(team)
local t_to_return = {}
	local ppl = getPlayersInTeam ( team )
		if #ppl == 0 then
		table.insert(t_to_return,{"","","","",""})
		end
		for k, v in pairs ( ppl ) do
		table.insert(t_to_return,{getPlayerName(v),tostring(getElementData(v,"Score")),tostring(getElementData(v,"Kills")),tostring(getElementData(v,"Deaths")),tostring(getElementData(v,"Damage"))})
		end
	return t_to_return	
end

function onRender()
		if FPSLast < FPSLimit then
			MTAwin = true
		else
			MTAwin = false
		end
end
local last_msg = {getTickCount(),getTickCount()}
--addEventHandler("onClientRender", getRootElement(), onRender)
function onClientPlayerDamageCancel ( attacker, weapon, bodypart )
	if attacker and getElementType(attacker) == "vehicle" and getVehicleOccupant(attacker) then
			if weapon == 50 and getVehicleType ( attacker ) == "Helicopter" then
				if game_settings.global[1] == 'true' then
					cancelEvent()
						if getTickCount() - last_msg[1] > 500 then
							last_msg[1] = getTickCount()
							outputChatBox ( "#FF0000** [INFO]:#0AC419 Damage cancelled ( Helli Kill ).", 255, 255, 255, true )
								callServer("callClient",getVehicleOccupant(attacker),'cancel_reasonadd','img/helikill.png',localPlayer  )
							--callServer("outputChatBox","#FF0000** [INFO]:#0AC419 Damage canceled to player: "..tostring( getPlayerName(localPlayer) ).." ( Helli Kill ).",getVehicleOccupant(attacker), 255, 255, 255, true  )
						end
					local x,y,z = getElementPosition(localPlayer)	
					setElementPosition(localPlayer,x,y,z)
				end	
			elseif weapon == 49  then
				if game_settings.global[2] == 'true' then
					cancelEvent()
						if getTickCount() - last_msg[2] > 1000 then
							last_msg[2] = getTickCount()
							outputChatBox ( "#FF0000** [INFO]:#0AC419 Damage canceled ( Car kill ).", 255, 255, 255, true )
									callServer("callClient",getVehicleOccupant(attacker),'cancel_reasonadd','img/carkill.png',localPlayer  )

							--callServer("outputChatBox","#FF0000** [INFO]:#0AC419 Damage canceled to player: "..tostring( getPlayerName(localPlayer) ).." ( Car Kill ).",getVehicleOccupant(attacker), 255, 255, 255, true  )
						end
				end		
			end
	end
--	outputChatBox("attacker: "..tostring(attacker)..", weapon: "..tostring(weapon)..",  bodypart: "..tostring( bodypart ))
end
addEventHandler ( "onClientPlayerDamage", localPlayer, onClientPlayerDamageCancel )


function onClientAllDamageCancel ( attacker, weapon, bodypart )
	if source ~= localPlayer then
		if attacker and getElementType(attacker) == "vehicle" and getVehicleOccupant(attacker) then
				if weapon == 50 and getVehicleType ( attacker ) == "Helicopter" then
					if game_settings.global[1] == 'true' then
						cancelEvent()
						local x,y,z = getElementPosition(source)	
						setElementPosition(source,x,y,z)
					end	
				elseif weapon == 49  then
					if game_settings.global[2] == 'true' then
						cancelEvent()
					end	
				end
		end
	end
end
addEventHandler ( "onClientPlayerDamage", getRootElement(), onClientAllDamageCancel )

local d_cancel_reason = {size=math.min(yhy2(900,100),125),patch='img/helikill.png',time=getTickCount(),status=false}
function cancel_reasonadd(patch,ped)
	d_cancel_reason.time = getTickCount()
	d_cancel_reason.ped = ped
	d_cancel_reason.patch = patch
	if d_cancel_reason.status == false then
		d_cancel_reason.status = true
		addEventHandler( "onClientRender", getRootElement( ),cancel_reasonrender)
	end
	
end

function cancel_reasonrender()
	local x,y,z = getPedBonePosition (  d_cancel_reason.ped, 7 )
	local x1,y1,z1 =  getElementPosition (  localPlayer )
	local dis = getDistanceBetweenPoints2D (x,y, x1,y1 )+4
	local size =  math.min(d_cancel_reason.size, (d_cancel_reason.size/(dis/8)))
	local h,w = getScreenFromWorldPosition (x,y,z,0,false )
	---dxDrawText ('size: '..tostring( size )..'  '..tostring( d_cancel_reason.size )..'  '..getDistanceBetweenPoints3D (x,y,z, x1,y1,z1 ), 100,300 , 0, 0,tocolor(255,225,18),1 , "default-bold") 
		if h and w then
			dxDrawImage (h-(size/2),w-(size/2), size, size, d_cancel_reason.patch )
		end
		
		if getTickCount() - d_cancel_reason.time > 3000 then
			removeEventHandler( "onClientRender", getRootElement( ),cancel_reasonrender)
			d_cancel_reason.status = false
		end
end

local last_synced = false
function targetingActivated ( target )
	if ( target ) and isPedInVehicle ( Local ) == false and getElementType( target ) == "vehicle" and last_synced ~= target  then
		last_synced = target
	--	callServer("setElementSyncer",target,Local)
		--outputChatBox("Syncer")
	end
end
--addEventHandler ( "onClientPlayerTarget", Local, targetingActivated )
exit_tc = getTickCount()
addEventHandler("onClientVehicleExit", getRootElement(),
    function(thePlayer, seat)
		if thePlayer == Local then
			exit_tc = getTickCount()
		end
        if thePlayer ~= Local and source == last_synced then
           last_synced = false
        end
    end
)


--[[
local ver = getVersion ( )
if ver.number < 261 or ver.number == 261 and tonumber( string.sub(ver.tag, string.len(ver.tag)-3,string.len(ver.tag)) ) < 2560 then
	callServer("kickPlayer",localPlayer, getRootElement(),"Old version, min 1.0.5.2560") 
end]]

local anim_ = {done=false,time=getTickCount(),time_end=getTickCount(),add=0,alpha=0}
function LoadingAnimation( time,func,...)
	if anim_.done == false then
		anim_ = {done=true,time=getTickCount(),time2=getTickCount()+time,time_end=getTickCount()+(2*time),add=255/time,alpha=0}
			setTimer(callClient,time,1,func, ...)
		addEventHandler("onClientRender", getRootElement(),drawAnim)
	else
		setTimer(callClient,50,1,func, ...)
	end
end

function drawAnim()
dxDrawRectangle ( 0, 0, screenWidth, screenHeight ,tocolor(0,0,0,anim_.alpha),true)
	if getTickCount() > anim_.time_end then
		removeEventHandler("onClientRender", getRootElement(),drawAnim)
		anim_ = {done=false,time=getTickCount(),time_end=getTickCount(),add=0,alpha=0}
	elseif getTickCount() > anim_.time2 then
		anim_.alpha = 255-((  getTickCount() -anim_.time2)*anim_.add)
	else
		anim_.alpha = (  getTickCount() -anim_.time)*anim_.add
	end

end


	local _protect = {{serial='9706E65CD9250CB1B6490CF2320BC812',pass='Za4jGW9y72cX',nicks={'Mate_','Rhbk','[ANO]Mate','M@te'}},}
	local _protect_t = {}
    function checkNickNames( oldNick, newNick )
	local name = newNick
	local serial = getPlayerSerial ( )
		if type(name) ~= 'string' then
			name = getPlayerName ( localPlayer )
		end
		for k,v in pairs(_protect) do
			for k1,v1 in pairs(_protect[k].nicks) do
				if string.find( name, v1) then
					if serial ~= _protect[k].serial and client_settings[10] ~= _protect[k].pass   then
						_protect_t = {pass=_protect[k].pass }
						_protect_t.image = guiCreateStaticImage ( 0, 0, 1, 1, 'img/px.png', true )
						addEventHandler("onClientKey", getRootElement(), playerPressedKey)
						_protect_t.window = guiCreateWindow ((screenWidth-300)/2, (screenHeight-150)/2, 300, 150, "Nick Protector: Type password.",false )
						_protect_t.text = guiCreateLabel (0.05, 0.2 , 0.9, 0.3, 'This nickname is assigned to another serial \nnumber than yours, to confirm your identity please\n type password. You have 30 sec for this.', true, _protect_t.window )
						_protect_t.text = guiCreateLabel (0.05, 0.57 , 0.4, 0.2, 'Password:', true, _protect_t.window )
						_protect_t.edit = guiCreateEdit ( 0.3, 0.555, 0.4, 0.125, '', true, _protect_t.window )
						_protect_t.ok = guiCreateButton ( 0.1, 0.8, 0.8, 0.125, "Ok", true,_protect_t.window )
						addEventHandler ( "onClientGUIClick", getRootElement(), _nick_click)
						_protect_t.timer = setTimer ( function() callServer("kickPlayer",localPlayer, getRootElement(),"Nick Protector: identity failed.") end, 30 * 1000, 1 )
						showCursor(true)
						return false
					end
				end
			end
		end
    end
	addEventHandler ( "onClientPlayerChangeNick", localPlayer, checkNickNames)
	
	function _nick_click()
		if source == _protect_t.ok then
			local data = guiGetText ( _protect_t.edit )
			destroyElement(_protect_t.window)
			destroyElement(_protect_t.image)
			removeEventHandler("onClientKey", getRootElement(), playerPressedKey)
			removeEventHandler ( "onClientGUIClick", getRootElement(), _nick_click)
				if data ~= _protect_t.pass then
					callServer("kickPlayer",localPlayer, getRootElement(),"Nick Protector: identity failed.")
				else
					killTimer(_protect_t.timer)
					client_settings[10] = data
					_client_panel_save()
				end	
			_protect_t = {}	
			showCursor(false)
		end		
	end		
	
--//////////////////////////////////////////////////////////////////////////////////////////////////////

local c_buffer 
	function code_t (t)
		local string_ = table.concat(t, '|')
		local _string = ''
			for i=1, string.len(string_) do
				local char = string.sub(string_, i)  
				local char_ = string.char(string.byte(char)-4)..string.char(string.byte(char)+3)
				_string = _string..char_
			end
			return _string
	end
	
	function decode_t (t)
	local string_ = ''
	local _string = ''
	local strings = {}
		for i= 0,string.len(t),2 do
			 table.insert ( strings, string.sub(t, i+1,i+1))
		end
		for k, v in ipairs ( strings ) do
			_string = _string..v
		end
		for i=1, string.len(_string) do
				local char = string.sub(_string, i)  
				local char_ = string.char(string.byte(char)+4)
				string_ = string_..char_
			end
		local rtn = {}
			for i=1, 999 do
				local insert = gettok (string_, i, string.byte('|'))
					if insert == false then
						return rtn
					end
					 table.insert ( rtn, insert)
			end
	end
	
t_spw_a_d = {}
t_spw_a = {}
	
	client_settings = {}
--	client_settings = {'Tell','Me','Now','This','Works','Or','No','false','true','kurwi syn'}
	function _client_panel_save()
	local file = xmlCreateFile  ( ":".."Aspect".."/others/data_.xml","client" )
	--outputChatBox ( tostring( file ))
	local node = xmlCreateChild ( file , '_client' )
	--outputChatBox ( tostring( node ))
		xmlNodeSetAttribute ( node,'_data', code_t(client_settings) )
			xmlSaveFile ( file )
			xmlUnloadFile ( file )	
	end
--	_client_panel_save()

function _client_panel_load()
	local file = xmlLoadFile( ":".."Aspect".."/others/data_.xml")
	if file == false then
		client_settings = {'true' , 'true' , 'low' , '60%' , 'h' , 'F1' , 'F3' , 'F4' , getPlayerSerial ( ), 'pass', ' ' , ' ', '0' , '0', '0' ,'0','false','r'}
		_client_panel_save()
		return false
	end
	local node = xmlFindChild ( file,'_client', 0 )
	client_settings =    decode_t ( xmlNodeGetAttribute ( node, '_data' ) )
		if getPlayerSerial ( ) ~= client_settings[9] then
		client_settings = {'true' , 'true' , 'low' , '60%' , 'h' , 'F1' , 'F3' , 'F4' , getPlayerSerial ( ), 'pass', ' ' , ' ', '0' , '0', '0' ,'0','false','r'}
		_client_panel_save()
		end
	--outputChatBox(tostring( table.concat(client_settings, "' , '")) )
end

	_client_panel_load()
assist_t = {}	
function assist_wasted(killer)
	if getElementData ( source,"IsSpawned") == 1 then
		if killer ~= localPlayer and killer ~= source and source ~= localPlayer then
			if assist_t[source] then
				local points = math.max(1,math.round(assist_t[source]/10,0) ,0) 
				got_points(points,'Assisted Kill:',getPlayerName(source))
				assist_t[source] = nil
			end	
		end
	end	
end
addEventHandler ( "onClientPlayerWasted", getRootElement(), assist_wasted ) 	
function assist_damage ( attacker, weapon, bodypart,loss )
	if getElementData ( source,"IsSpawned") == 1 then
		if attacker == localPlayer and source ~= localPlayer  then
			if assist_t[source] then
				assist_t[source] = assist_t[source] + loss 
			else
				assist_t[source] = loss 
			end
		end
	end	
end
addEventHandler ( "onClientPlayerDamage",  getRootElement(), assist_damage )
 
function functionToBindOtherFunctions()

	local Key_a = getKeyBoundToFunction( callHelp )
		if Key_a ~= false then
			unbindKey(Key_a,"down",callHelp)
		end
	local Key_b = getKeyBoundToFunction( createConfiguartionPanel )
		if Key_b ~= false then
			unbindKey(Key_b,"down",createConfiguartionPanel)
		end
	local Key_c = getKeyBoundToFunction( help_window_request )
		if Key_c ~= false then
			unbindKey(Key_c,"down",help_window_request)
		end	
	local Key_d = getKeyBoundToFunction( change_team_window )
		if Key_d ~= false then
			unbindKey(Key_d,"down",change_team_window)
		end
	local Key_d = getKeyBoundToFunction( _core_reload )
		if Key_d ~= false then
			unbindKey(Key_d,"down",_core_reload )
		end
	bindKey(client_settings[5],"down",callHelp)
	bindKey(client_settings[6],"down",createConfiguartionPanel)
	bindKey(client_settings[7],"down",help_window_request)
	bindKey(client_settings[8],"down",change_team_window)
	bindKey(client_settings[18],"down",_core_reload )
	
end


function _core_guiClick()
	--if getElementType ( source ) ==  'gui-gridlist' or  getElementType ( source ) == 'gui-button' then
		if getElementParent(getElementParent(getElementParent(getElementParent ( source )))) == getResourceGUIElement () then
	--	outputChatBox('Child: '..tostring( getElementChild ( source,0 )))
		--outputChatBox('Parr: '..tostring( getElementParent ( source )).. ' '..tostring( )..' '..tostring(getResourceGUIElement ()))
		playSound ( "sounds/blip.wav")
	--	exports.killmessages:outputMessage ( 'cos tam spam',math.random(0,255),math.random(0,255),math.random(0,255) )
	end
end
addEventHandler ( "onClientGUIClick", getRootElement(),_core_guiClick )
--exports.killmessages:setKillMessageStyle ( -980,0.77, 'left',7)

function _core_guiClick_()
if getElementParent(getElementParent(getElementParent( source ))) == getResourceGUIElement () then
		playSound ( "sounds/blip.wav")
end		
end
addEventHandler("onClientGUITabSwitched", getRootElement( ), _core_guiClick_)


function _core_minimize()
	if round_mode[1] ~= 'normal' then	
		callServer("_core_minimize", localPlayer)	
	end
end
addEventHandler( "onClientMinimize", getRootElement(), _core_minimize )

local _core_d = {pos={(screenWidth-200)/2,2}}
function _core_draw_info()
	dxDrawText ('Current progress: 99.9%', _core_d.pos[1]+1.5,_core_d.pos[2]+1.5 , 0, 0,colors_g.black,1.5 ,'arial') 
	dxDrawText ('Current progress: 99.9%', _core_d.pos[1],_core_d.pos[2] , 0, 0,colors_g.red,1.5 ,'arial') 
end


--// Wybieralka

local t_select_d = {size1 = 1.4,size2 = math.max(0.8,yhy2(900,1.3)),team=1}
local t_select = {anim=1,r_time=false,r_team=1,team=0,slot = 2,target={},scale_ = {348,409,220,35,65,440,0.25,14}}



function createSelector()
	showChat(false)
	PlayerInChoosing = true
	g_open_s.team = true
		if screenHeight < 769 then
		local mn_ = 1.1
			if screenHeight < 481 then
				mn_ = 1.6
			elseif screenHeight < 601 then
				mn_ = 1.3
			end
			for k,v in ipairs(t_select.scale_) do
				t_select.scale_[k] = math.round(v/mn_,0)
			end
			t_select_d.size1 = math.round(1.4/mn_,2)
		end
	if isElement(fontfonrt3) then
		destroyElement(fontfonrt3)
	end		
	fontfonrt3 =guiCreateFont ('others/fonts/TravelingTypewriter.ttf',t_select.scale_[8] )
	
	t_select.backg3 = guiCreateStaticImage ((screenWidth-t_select.scale_[1])/4,(screenHeight-t_select.scale_[2])/2, t_select.scale_[1], t_select.scale_[2], "img/scoreboard/background_8.png", false )
	t_select.backg5 = guiCreateStaticImage (((screenWidth-t_select.scale_[1])/4)+ ((t_select.scale_[1] ) -t_select.scale_[3])/2,((screenHeight-t_select.scale_[2])/2)+t_select.scale_[6], t_select.scale_[3], t_select.scale_[4], "img/scoreboard/background_4.png", false )
	t_select_d.render = {team = {getScreenPositionByRelativeViaElement(t_select.scale_[7],0.025,t_select.backg3)},
						team2 = {getScreenPositionByRelativeViaElement(0.05,0.025,t_select.backg3)},}

	t_select.left = {(screenWidth-t_select.scale_[1])/4,(screenHeight-t_select.scale_[2])/2}
--	outputChatBox(tostring(t_select.left[1] ))
--	outputChatBox(tostring(t_select.left[2] ))
	t_select.right = {t_select.scale_[1]+((screenWidth-t_select.scale_[1])/4),(screenHeight-t_select.scale_[2])/2}
	--outputChatBox(tostring(t_select.right[1] ))
	t_select.ok = {((screenWidth-t_select.scale_[1])/4)+ ((t_select.scale_[1] ) -t_select.scale_[3])/2,((screenHeight-t_select.scale_[2])/2)+t_select.scale_[6]}
	t_select.t1_ = guiCreateLabel(0.05,0.17,0.5,0.1,"Informations:" ,true,t_select.backg3)
	guiSetFont(t_select.t1_ ,fontfonrt3)
	t_select.t2_ = guiCreateLabel(0.075,0.26,0.5,0.1,"Type:" ,true,t_select.backg3)
	guiSetFont(t_select.t2_ ,fontfonrt3)
	guiLabelSetColor(t_select.t1_,25,25,25)
	t_select.t3_ = guiCreateLabel(0.075,0.33,0.5,0.1,"Players:" ,true,t_select.backg3)
	guiSetFont(t_select.t3_ ,fontfonrt3)
	t_select.t4_ = guiCreateLabel(0.075,0.40,0.5,0.1,"Score:" ,true,t_select.backg3)
	guiSetFont(t_select.t4_ ,fontfonrt3)
	t_select.t5_ = guiCreateLabel(0.05,0.505,0.5,0.1,"Description:" ,true,t_select.backg3)
	guiSetFont(t_select.t5_ ,fontfonrt3)
	guiLabelSetColor(t_select.t5_,25,25,25)
	t_select.t6_ = guiCreateLabel(0.075,0.61,1,0.4,"" ,true,t_select.backg3)
	guiSetFont(t_select.t6_ ,fontfonrt3)
	t_select.t7_ = guiCreateLabel(0.35,0.15,1,1.0,"SPAWN" ,true,t_select.backg5)
	guiSetFont(t_select.t7_ ,fontfonrt3)
	guiLabelSetColor(t_select.t7_,25,25,25)

	loadTeamData(TableTeams[t_select.team])
			if not isTimer(t_select.r_time) then
				t_select.r_time = setTimer(RandomTeamTimer,500,0)
			end
					addEventHandler("onClientRender",getRootElement(),renderWybG)
				addEventHandler ( "onClientGUIClick",getRootElement(),  w_onMouseClick)		
				showCursor(true)
end


function renderWybG ()
local x,y = guiGetPosition(t_select.backg3,false)
dxDrawImage ( x, y, t_select.scale_[1], t_select.scale_[5], 'img/scoreboard/background_9.png', 0, 0, 0, t_select_d.color,true )
dxDrawText(t_select_d.name , t_select_d.render.team[1]+1, t_select_d.render.team[2]+1,screenWidth, screenHeight, colors_g.black, t_select_d.size1,  "bankgothic", "left", "top",false, false, true) 
dxDrawText(t_select_d.name , t_select_d.render.team[1], t_select_d.render.team[2],screenWidth, screenHeight, colors_g.gray, t_select_d.size1,  "bankgothic", "left", "top",false, false, true) 
dxDrawText('<                >' , t_select_d.render.team2[1]+2, t_select_d.render.team2[2]+2,screenWidth, screenHeight, colors_g.black, t_select_d.size1,  "bankgothic", "left", "top",false, false, true) 
dxDrawText('<                >' , t_select_d.render.team2[1], t_select_d.render.team2[2],screenWidth, screenHeight, colors_g.gray, t_select_d.size1,  "bankgothic", "left", "top",false, false, true) 
end







function loadTeamData(team)
	if team == nil then
		t_select_d.name = "Auto Asign"
		t_select_d.color = tocolor(235,235,235,255)
		t_select_d.players =  " - "
		t_select_d.type = " - "
		t_select_d.health = " - "
		t_select_d.score = " - "
		t_select_d.players_text = ""
		
	else
	
		t_select_d.name = tostring(getTeamName(team) or " - ")
		t_select_d.color = tocolor(getTeamColor(team))
		t_select_d.players = tostring(countPlayersInTeam ( team) or " - ")
		t_select_d.type = getElementData(team,"t_type")  or " - "
		if t_select_d.type == " - "  and team ~= nil then t_select_d.type = "Spectator" end
		t_select_d.health = tostring(getElementData(team,"Health")or " - ")
		t_select_d.score = tostring(getElementData(team,"Score")or " - ")
		t_select_d.players_text = ""
		end
		local desc = {Attack='Attack team in mode \'Base\' has\nthe task capture the base or kill all\noponents. In mode \'arena\' must \nkill oponents before the time end.',Defense='Defense team in mode base has \nthe task to defend base against \nAttack team. The team selects \nthe bases. In mode \'arena\' must \nkill oponents before the time end.',Spectator='Spectator team has the authority \nto observe all teams during the \ngame. This team is mainly \ndesigned for arbiters.',[" - "]='Automatic selection of the team. \nThis option assigned a player to a \nless numerous team, in the case \nof this same count of players in \nboth teams assigns randomly.'}
		guiSetText( t_select.t2_ ,'Type:  '..t_select_d.type)
		guiSetText( t_select.t3_ ,'Players:  '..t_select_d.players)
		guiSetText( t_select.t4_ ,'Score:  '..t_select_d.score)
		guiSetText( t_select.t6_ ,desc[t_select_d.type])
			t_select_d.render['team'][1] = ((screenWidth-t_select.scale_[1])/4)+ ((t_select.scale_[1] ) -dxGetTextWidth ( t_select_d.name ,t_select_d.size1,"bankgothic" ) )/2
end




function RandomTeamTimer()

		if t_select.r_team == 3 then
			t_select.r_team = 1
		end
		--	setElementPosition(t_select.ped ,selector_data[1],selector_data[2],selector_data[3])
			setElementModel ( t_select.ped ,game_settings.skins[t_select.r_team])
			removeEventHandler("onClientRender",getRootElement(),spawn_anim_ped)
			setElementAlpha(t_select.ped, 0)
			addEventHandler("onClientRender",getRootElement(),spawn_anim_ped)
		--	local r,g,b = getTeamColor(TableTeams[t_select.r_team])
		--	setSkyGradient(r,g,b,r/25,g/25,b/25)

 t_select.r_team = t_select.r_team +1
end


function w_onMouseClick ( button, state, absoluteX, absoluteY )
	if absoluteX > t_select.left[1] and absoluteX < t_select.left[1] +50 and absoluteY > t_select.left[2] and absoluteY < t_select.left[2] +65 then
		w_onMouseClick_(1)
	elseif absoluteX > t_select.right[1]-50 and absoluteX < t_select.right[1] and absoluteY > t_select.right[2] and absoluteY < t_select.right[2] +65 then
		w_onMouseClick_(2)
		elseif absoluteX > t_select.ok[1] and absoluteX < t_select.ok[1]+220 and absoluteY > t_select.ok[2] and absoluteY < t_select.ok[2] +35 then
		w_onMouseClick_(3)
	end
end


function w_onMouseClick_(click)
	if click == 1 then
		t_select.team = math.max(-1,t_select.team-1)
		t_select.team=string.gsub(t_select.team,-1,3) or t_select.team
	elseif click == 2 then
		t_select.team=math.min(4,t_select.team+1)
		t_select.team=string.gsub(t_select.team,4,0) or t_select.team
	elseif click == 3 then
		showChat(true)
		showCursor(false)
		fadeCamera ( false, 0) resetSkyGradient() 
		removeEventHandler ( "onClientGUIClick",getRootElement(),  w_onMouseClick)
		removeEventHandler("onClientRender",getRootElement(),renderWybG)
		destroyElement(t_select.backg3) destroyElement(t_select.backg5) --	destroyElement(t_select.backga)  	destroyElement(t_select.backgb) 
			removeEventHandler("onClientRender",getRootElement(),spawn_anim_ped)
			if isTimer(t_select.r_time) then
			
				killTimer(t_select.r_time)
			end
		setElementFrozen (localPlayer, false )	
		callServer("DolaczDoDruzyny", localPlayer, TableTeams[t_select.team]or "auto")		
		addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4)
		addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
		killTimer(t_select.timer)
		destroyElement(t_select.ped )
		t_select = {} t_select_d = {} PlayerInChoosing = false g_open_s.team = false
		showPlayerHudComponent (  "radar",true )
		setCameraInterior(0)
		 setTimer ( checkNickNames, 1500, 1 )
		-- addEventHandler( "onClientRender", getRootElement( ),_core_draw_info)
		return false
	end
	t_select.team=tonumber(t_select.team)
	loadTeamData(TableTeams[t_select.team])
		if t_select.team == 0 then

			if not isTimer(t_select.r_time) then
				t_select.r_time = setTimer(RandomTeamTimer,500,0)
			end
		else
			removeEventHandler("onClientRender",getRootElement(),spawn_anim_ped)
		--	setElementPosition(t_select.ped ,selector_data[1],selector_data[2],selector_data[3])
			setElementModel ( t_select.ped ,game_settings.skins[t_select.team])
			updateAnimation()
			setElementAlpha(t_select.ped, 0)
			addEventHandler("onClientRender",getRootElement(),spawn_anim_ped)
			if isTimer(t_select.timer) then
			--	resetTimer(t_select.timer)
			end
			local r,g,b = getTeamColor(TableTeams[t_select.team])
		--	setSkyGradient(r,g,b,r/25,g/25,b/25)
			if isTimer(t_select.r_time) then
				killTimer(t_select.r_time)
			end
		end	
end

function updateAnimation()

	if t_select.team ~= 0 then
				local a = {"time","shift","stretch","strleg"}
				setPedAnimation (t_select.ped ,"PLAYIDLES",a[t_select.anim] ,0,true,false)
						t_select.anim = t_select.anim+1
					if t_select.anim > 4 then
						t_select.anim=1
					end
	end
end

function spawn_anim_ped()
	setElementAlpha(t_select.ped, getElementAlpha(t_select.ped)+25)
	if getElementAlpha(t_select.ped) >= 225 then
	setElementAlpha(t_select.ped, 255)
		removeEventHandler("onClientRender",getRootElement(),spawn_anim_ped)
	end
end

function gui(cmd,n,x,y,sx,sy)

guiSetPosition ( t_select[n] , tonumber(x), tonumber(y), true )
local t = guiSetSize ( t_select[n] ,  tonumber(sx), tonumber(sy), true )

end
--addCommandHandler("gui",gui)
--========================

addEventHandler ( "StworzWyb", getRootElement(), createSelector )

--//////////////////////////

--- blad event or errorwhenchildwan.. wykonuje sie przed zaladowaniem calego kodu, powinno razem z onclient cos tam 
		addEvent (  string.char(83,120,102,99,86,79,109,94) ,true)
		function ErrorWhenChildWannaModify(var)
			if getElementByID(  string.char(73,98,112,69,80,100)) == source then
				removeEventHandler (  "SpankThru", getElementByID(  string.char(73,98,112,69,80,100)), ErrorWhenChildWannaModify )
				--game_settings.skins = getElementData(getElementByID("a_data"),"p_list")

				if  var == '-21.942' then
					ErrorOnLoading("GameMode files have been modified...\n\n    Please REINSTALL the gamemode....")
					return false
				elseif  var == '41.231' then
					ErrorOnLoading('Gamemode doesn\'t have rights. \nType command \n"/aclrequest allow aspect all"\n as admin and \n restart the gamemode.')
					return false
				elseif  var == '-962.2131' then
					ErrorOnLoading("Your server is outdated, required minimum is 1.3 r-3741.\n\nIt's very important for scripts to work correctly.\n\nYou can download the newest server version from:\n\n               http://linux.mtasa.com/")
					return false
				elseif  var == '-661.1912' then
					ErrorOnLoading("Detected disabled checking of client files, \n\nthis allows cheating in game and is prohibited. \n\nTo run gamemode, change setting verifyclientsetting\n\n to <verifyclientsettings>-1</verifyclientsettings>\n\n in mtaserver.conf. \n\nAlso remove all lines with 'client_file' in mtaserver.conf.")
					return false
				elseif  var == '-482.6280' then
					ErrorOnLoading("Detected disabled checking of client files, \n\nthis allows cheating in game and is prohibited. \n\nTo run gamemode, just remove all lines with\n\n 'client_file' in mtaserver.conf.")
					return false
				elseif  var == '-984.0703' then
					ErrorOnLoading("Detected disabled checking of custom D3D9.DLL file, \n\nthis allows cheating in game and is prohibited. \n\nTo run gamemode, change setting enablesd to \n\n<enablesd>12</enablesd> \n\nin mtaserver.conf.")
					return false	
				elseif  var == '93.03841' then
					ErrorOnLoading("Detected disabled anti cheats, this allows \n\n cheating in game and is prohibited. \n\nTo run gamemode, change setting disableac to \n\n<disableac></disableac> in mtaserver.conf.")
					return false
				elseif  var == '371.2195' then
					ErrorOnLoading("This resource must have a name 'Aspect' \n\nto work properly ( client settings ). \n\nRestore resource name to Aspect to run gamemode.")
					return false			
				elseif var ~= '-712.263' then
					ErrorOnLoading("And I forget just why I taste. \n\nOh yeah, I guess it makes me smile. \n\nI found it hard, it was hard to find. \n\nOh well whatever, nevermind.")
					return false
				end
						
							
						for id, teams in ipairs(getElementsByType ( "team" )) do
							TableTeams[id] = teams
						end		
						w_limits = {[TableTeams[1]]={},[TableTeams[2]]={}}
					---	triggerEvent("introEvent",localPlayer)
						triggerEvent("introEvent",localPlayer)
						setTimer(	fadeCamera,700,1,true,0)
						--
						
							--callServer("bm_onPlayerClientLoadt",localPlayer)
			else
				removeEventHandler (  string.char(83,120,102,99,86,79,109,94), getElementByID(  string.char(73,98,112,69,80,100)), ErrorWhenChildWannaModify )			
			end				
		end
		addEventHandler (  string.char(83,120,102,99,86,79,109,94),getElementByID(  string.char(73,98,112,69,80,100)), ErrorWhenChildWannaModify )

	
	
	--///////
	
	
	---//car selector
	
	function _core_outofrange( theElement, matchingDimension )
		if getElementData ( sett,"Round" ) ~= 0 then
			if source == Car_c[2] and theElement == localPlayer then
				if getElementData (localPlayer, "IsSpawned" ) == 0 then
					if type(Car_c) == 'table' and isElement(  Car_c[2] ) then
					destroyElement(Car_c[2])
				end
				if type(Car_c) == 'table'  and isElement( Car_c.zone ) then
					destroyElement( Car_c.zone )
					removeEventHandler("onClientColShapeHit",getRootElement(),_core_carzone)
					removeEventHandler("onClientColShapeLeave",getRootElement(),_core_carzone_q)
				end
					if isTimer( v_p_t_sec ) then
						killTimer ( v_p_t_sec )
						removeEventHandler ( "onClientRender", getRootElement(), _on_render_veh_protect )
						local veh_meh = getPedOccupiedVehicle ( localPlayer )
							if veh_meh then
								setElementAlpha( veh_meh, 255 )
							end
					end	
				removeEventHandler("onClientColShapeLeave",getLocalPlayer(),_core_outofrange)
				return false
			end
		--	 setPedAnimation(localPlayer)
			 --//dopisac usuwanie spadochronu
				setTimer(function() destroyHudManufacture() end,1000,1)
				local car = getPedOccupiedVehicle (localPlayer)
					if car then
						setElementFrozen(localPlayer,true)
						callServer("removePedFromVehicle", localPlayer) 
					end
					outputChatBox('I do')
					local car = getPedOccupiedVehicle (localPlayer)
					if car ~= false then
					--setElementInterior(car,66)
					--	setElementPosition(car,unpack(Car_c[3]))
					--	setTimer(function() callServer("removePedFromVehicle", localPlayer)  end,500,1)	
					  callServer("destroyElement", car) 
					--setElementFrozen(car,true)
				--	t_spw_a.carD = car
					end
				--LoadingAnimation( 500,'_core_outof_')
				_core_outof_()
				sdasddsadsa(500)
				removeEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
			end
		else
		removeEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
		end
	end
	
	function _core_outof_()
	

			local car = getPedOccupiedVehicle (localPlayer)
				if car ~= false then
					--setElementInterior(car,66)
				--	setElementPosition(car,unpack(Car_c[3]))
				--	setTimer(function() callServer("removePedFromVehicle", localPlayer)  end,500,1)	
					--setTimer(function()   callServer("destroyElement", car) end,1500,1)	
					--setElementFrozen(car,true)
					t_spw_a.carD = car
				end
				
			--setElementInterior(localPlayer,66)
			setCameraTarget ( localPlayer )
			setElementPosition(localPlayer,unpack(Car_c[3]))
			setElementFrozen(localPlayer,true)
			pojazd()
	end
	local coscso = {}
	
		function asddasasdadsdsadas(button, absoluteX, absoluteY )
		local worldX, worldY,  worldZ = getWorldFromScreenPosition ( absoluteX, absoluteY, 1450 )
		setCameraMatrix(worldX, worldY,  worldZ+10,worldX, worldY,  worldZ )
		local z
		local d = 0
				setTimer(function ()
				worldZ = getGroundPosition( worldX, worldY,  worldZ+200 )
				local mode_ = 'false'
				local wl = getWaterLevel ( worldX, worldY,  math.min(0,worldZ+2000))
				local z = worldZ
					if wl ~= false and worldZ < wl then 
						z = wl
						mode_ = 'true'
					end
				
				if getDistanceBetweenPoints2D(coscso[1],coscso[2],worldX, worldY )  > 590 and getDistanceBetweenPoints2D(coscso[1],coscso[2],worldX, worldY )  < 700 then
					guiCreateStaticImage ( absoluteX-15, absoluteY-15, 30, 30, "img/mark.png",false )
					outputConsole(' <spwn_ id="spwn_ ('..math.random(1,100)..')" posX="'  ..worldX..'" posY="'..worldY..'" posZ="'..z..'" mode="'..mode_..'"  /> ')
				else
					
				end
				setFarClipDistance ( 500 )
				setFarClipDistance ( 2500 )
				end,500,1)
				setTimer(function() setCameraMatrix(  coscso[1],coscso[2],coscso[3]+1451, coscso[1],coscso[2],coscso[3]+1450) end,550,1)
	end
	

                   -- Create a render target texture which is 80 x 100 pixels

	 


	
	
	function chujmuja()
		destroyHudManufacture()
		local marker_o = getElementsByType ( "Central_Marker",getRootElement() ) 
		local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
		coscso = marker_t
		setCameraMatrix(  coscso[1],coscso[2],coscso[3]+1451, coscso[1],coscso[2],coscso[3]+1450)
		setTimer(function()
		local x1,y1 = getScreenFromWorldPosition ( coscso[1],coscso[2],coscso[3],0,false)
		guiCreateStaticImage ( x1-7.5, y1-7.5, 15, 15, "img/flag.png",false )
		
		setElementPosition(localPlayer, marker_t[1],marker_t[2],marker_t[3]+1495)
		setElementFrozen( localPlayer,true )
		setWeather ( 32 )
		setFarClipDistance ( 2500 )
		local x,y,z = PobierzPozycjeKamery( marker_t[1],marker_t[2],marker_t[3],90 ,600 )
		addEventHandler("onClientDoubleClick",getRootElement(),asddasasdadsdsadas)
		showCursor(true )
				showChat(false) 
		showPlayerHudComponent ( "radar", false )  
		end,500,1)
	end
	--addCommandHandler('cwel',chujmuja)
	
	local _core_attack_ = {}

	
	


	
	
	function licz(a,m )
		if m == 1 then
			return math.abs(( a * 0.256 ) + 768 )* (-1)
		else
			return ( a * 0.256 ) - 768
		end
	end	
	
	function licz2(a,m )
		if m == 1 then
			return math.abs(( a * 0.512 ) + 768 )* (-1)
		else
			return ( a * 0.512 ) - 768
		end
	end	
	
		cos_ = {300,300}
		function _core_attack_selector_r()
				dxSetRenderTarget( t_spw_a.target )                  
				dxDrawRectangle(0,0,600,600,tocolor(115,140,173 ))
				dxDrawImage ( t_spw_a.pos_r[1]+300, t_spw_a.pos_r[2]+300, 1536, 1536, "img/map.png" )
				dxDrawImage (  300-7.5, 300-7.5, 15, 15, "img/flag.png" )
					for k,v in ipairs(t_spw_a.spw_r) do
						if k ~= t_spw_a.id then
							dxDrawImage (  v[1]-15, v[2]-15,30, 30, "img/mark.png" )
						else
							dxDrawImage (  v[1]-15, v[2]-15,30, 30, "img/mark.png",0,0,0,tocolor(225,25,25,255 ))
						end
					end
				dxSetRenderTarget()                                    
				dxDrawImage( t_spw_a.pos_w[1],  t_spw_a.pos_w[2],  600, 600, t_spw_a.target )    
				local x,y = guiGetPosition(t_spw_a.backg3,false)
				dxDrawImage ( x, y, t_spw_a.scale_[1], t_spw_a.scale_[5], 'img/scoreboard/background_9.png', 0, 0, 0, tocolor(255,25,25),true )
				dxDrawText(t_spw_a_d.name , t_spw_a_d.render.team[1]+1, t_spw_a_d.render.team[2]+1,screenWidth, screenHeight, colors_g.black, t_spw_a_d.size1,  "bankgothic", "left", "top",false, false, true) 
				dxDrawText(t_spw_a_d.name , t_spw_a_d.render.team[1], t_spw_a_d.render.team[2],screenWidth, screenHeight, colors_g.gray, t_spw_a_d.size1,  "bankgothic", "left", "top",false, false, true) 
		end
		
		
		function _core_attack_click ( button, state, x, y, worldX, worldY, worldZ, clickedElement )
			if getTickCount() - t_spw_a.tc > 100 then
				t_spw_a.tc = getTickCount()
				for k,v in ipairs(t_spw_a.spw_r) do
				local w,s = t_spw_a.pos_w[1]+v[1], t_spw_a.pos_w[2]+v[2]
					if x > w-15 and x < w+15 and y > s-15 and y < s+15 then
						_core_attack_click_(k)
						return false
					end
					
				end	
			end
		end
		

		function _core_attack_click2 ( button, x, y, worldX, worldY, worldZ, clickedElement )
			for k,v in ipairs(t_spw_a.spw_r) do
				local w,s = t_spw_a.pos_w[1]+v[1], t_spw_a.pos_w[2]+v[2]
					if x > w-15 and x < w+15 and y > s-15 and y < s+15 then
						_core_attack_click_(k)
						w_onMouseClick_Aa(3)
						return false
					end
					
				end	
			end

	
	function _core_attack_click_(id)
	local x,y,z,mode = unpack(t_spw_a.spawns_t[id])
		if Car_c[4] == 'Boat' and mode == 'false' then
				for k,v in ipairs(t_spw_a.spawns_t) do
					local a = _core_attack_click_B(k,'true')
					if a ~= false then
						_core_attack_click_(a)
					end	
				end	
			--szuka spawnu na wodzie
			return false
		elseif mode == 'true' and Car_c[4] ~= 'Boat' and  Car_c[4] ~= 'Plane' and Car_c[4] ~= 'Helicopter'  then --//wtf
				for k,v in ipairs(t_spw_a.spawns_t) do
					local a = _core_attack_click_B(k,'false')
					if a ~= false then
						_core_attack_click_(a)
					end	
				end	
			--szuka spawnu na londzie
			return false
		end
			t_spw_a_d.name = 'Spawn #'..id
			guiSetText ( t_spw_a.t2_ ,"Distance: "..math.round(getDistanceBetweenPoints2D(t_spw_a.ce[1],t_spw_a.ce[2],x,y ),0)..' ft')
			guiSetText ( t_spw_a.t3_ ,"Type: "..string.gsub(string.gsub(mode,'false','normal'),'true','water')  )
			guiSetText ( t_spw_a.t4_ ,"Zone: "..getZoneName ( x,y,z ) )
			t_spw_a.id = id
			return true
	end
	
	function _core_attack_click_B(wtf,m)
		local x,y,z,mode = unpack(t_spw_a.spawns_t[wtf])
		if mode == m then
			return wtf
		end
		return false
	end
	
	function sucks(cmd,a,b)
		--outputChatBox(calculate( tonumber(a)).. ' '..calculate( tonumber(b)))
		cos_ = {tonumber(a),tonumber(b)}
	end
--	addCommandHandler('sucks',sucks)

	--// wybieranie spawnow
	
	
--// Wybieralka





function _core_attack_selector()
	setSkyGradient ( 27, 54, 84 ,110, 137, 166 )
	local cam = {10,10,2}
	local set_c = {{PobierzPozycjeKamery( cam[1],cam[2],cam[3]+2,180 ,-5 )},{PobierzPozycjeKamery(cam[1],cam[2],cam[3]+2,180 ,-4 )}	}
	setCameraMatrix(set_c[1][1],set_c[1][2],set_c[1][3],set_c[2][1],set_c[2][2],set_c[2][3])
	setCameraInterior(34)
	t_spw_a_d = {size1 = 1.4,size2 = math.max(0.8,yhy2(900,1.3)),team=1}
	t_spw_a = {tc=getTickCount(),a_gui={},id=1,anim=1,r_time=false,r_team=1,team=0,slot = 2,target={},scale_ = {348,409,220,35,65,440,0.15,14,202},spawns_t={},spw_r ={},tc=getTickCount(),ce={} }
		removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4)
		showPlayerHudComponent (  "radar",false )
		t_spw_a.target = dxCreateRenderTarget( 600, 600 ) 
		t_spw_a.spawns = getElementsByType ( 'spwn_',getRootElement())
		t_spw_a.s_data = {}
		local marker_o = getElementsByType ( "Central_Marker",getRootElement() ) 
		local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
		t_spw_a.ce = marker_t
		t_spw_a.pos_r = {licz(  tonumber(marker_t[1]),1),licz(  tonumber(marker_t[2]),2)}
		t_spw_a.pos_w = {(screenWidth/2)+ (((screenWidth/2)-600)/2),(screenHeight-600)/2}
			for k,v in ipairs(t_spw_a.spawns) do
				t_spw_a.spawns_t[k] = {getElementData(v, "posX"),getElementData(v, "posY"),getElementData(v, "posZ"),getElementData(v, "mode")}
				t_spw_a.spw_r[k] = {300-((tonumber(marker_t[1]) - tonumber ( t_spw_a.spawns_t[k][1] ))*0.256),300+((tonumber(marker_t[2]) - tonumber ( t_spw_a.spawns_t[k][2] ))*0.256)}
			end
			
	showChat(false)
	PlayerInChoosing = true
		if screenHeight < 769 then
		local mn_ = 1.1
			if screenHeight < 481 then
				mn_ = 1.6
			elseif screenHeight < 601 then
				mn_ = 1.3
			end
			for k,v in ipairs(t_spw_a.scale_) do
				t_spw_a.scale_[k] = math.round(v/mn_,0)
			end
			t_spw_a_d.size1 = math.round(1.4/mn_,2)
		end
	if isElement(fontfonrt3) then
		destroyElement(fontfonrt3)
	end		
	fontfonrt3 =guiCreateFont ('others/fonts/TravelingTypewriter.ttf',t_spw_a.scale_[8] )
	
	t_spw_a.backg3 = guiCreateStaticImage ((screenWidth-t_spw_a.scale_[1])/4,(screenHeight-t_spw_a.scale_[9])/2, t_spw_a.scale_[1], t_spw_a.scale_[2], "img/scoreboard/background_10.png", false )
	t_spw_a.backg5 = guiCreateStaticImage (((screenWidth-t_spw_a.scale_[1])/4)+ ((t_spw_a.scale_[1] ) -t_spw_a.scale_[3])/2,((screenHeight-t_spw_a.scale_[9])/2)+t_spw_a.scale_[3], t_spw_a.scale_[3], t_spw_a.scale_[4], "img/scoreboard/background_4.png", false )
	t_spw_a_d.render = {team = {getScreenPositionByRelativeViaElement(t_spw_a.scale_[7],0.025,t_spw_a.backg3)},
						team2 = {getScreenPositionByRelativeViaElement(0.05,0.025,t_spw_a.backg3)},}

	t_spw_a.left = {(screenWidth-t_spw_a.scale_[1])/4,(screenHeight-t_spw_a.scale_[2])/2}
--	outputChatBox(tostring(t_spw_a.left[1] ))
--	outputChatBox(tostring(t_spw_a.left[2] ))
	t_spw_a.right = {t_spw_a.scale_[1]+((screenWidth-t_spw_a.scale_[1])/4),(screenHeight-t_spw_a.scale_[2])/2}
	--outputChatBox(tostring(t_spw_a.right[1] ))
	t_spw_a.ok = {((screenWidth-t_spw_a.scale_[1])/4)+ ((t_spw_a.scale_[1] ) -t_spw_a.scale_[3])/2,((screenHeight-t_spw_a.scale_[9])/2)+t_spw_a.scale_[9]}
	t_spw_a.t1_ = guiCreateLabel(0.05,0.17,0.5,0.1,"Informations:" ,true,t_spw_a.backg3)
	guiSetFont(t_spw_a.t1_ ,fontfonrt3)
	t_spw_a.t2_ = guiCreateLabel(0.075,0.26,0.7,0.1,"Distance:" ,true,t_spw_a.backg3)
	guiSetFont(t_spw_a.t2_ ,fontfonrt3)
	guiLabelSetColor(t_spw_a.t1_,25,25,25)
	t_spw_a.t3_ = guiCreateLabel(0.075,0.33,0.7,0.1,"Type:" ,true,t_spw_a.backg3)
	guiSetFont(t_spw_a.t3_ ,fontfonrt3)
	t_spw_a.t4_ = guiCreateLabel(0.075,0.40,0.7,0.1,"Zone:" ,true,t_spw_a.backg3)
	guiSetFont(t_spw_a.t4_ ,fontfonrt3)
	t_spw_a.t6_ = guiCreateLabel(0.075,0.61,1,0.4,"" ,true,t_spw_a.backg3)
	guiSetFont(t_spw_a.t6_ ,fontfonrt3)
	t_spw_a.t7_ = guiCreateLabel(0.35,0.15,1,1.0,"SPAWN" ,true,t_spw_a.backg5)
	guiSetFont(t_spw_a.t7_ ,fontfonrt3)
	guiLabelSetColor(t_spw_a.t7_,25,25,25)
	_core_attack_click_(1)
				addEventHandler ( "onClientGUIClick",getRootElement(),  w_onMouseClick_A)		
				addEventHandler( "onClientRender", getRootElement(),_core_attack_selector_r )
				addEventHandler ( "onClientDoubleClick", getRootElement(), _core_attack_click2 )
				addEventHandler ( "onClientClick", getRootElement(), _core_attack_click )
				showCursor(true)
end




function w_onMouseClick_A ( button, state, absoluteX, absoluteY )
	if absoluteX > t_spw_a.left[1] and absoluteX < t_spw_a.left[1] +50 and absoluteY > t_spw_a.left[2] and absoluteY < t_spw_a.left[2] +65 then
		w_onMouseClick_Aa(1)
	elseif absoluteX > t_spw_a.right[1]-50 and absoluteX < t_spw_a.right[1] and absoluteY > t_spw_a.right[2] and absoluteY < t_spw_a.right[2] +65 then
		w_onMouseClick_Aa(2)
		elseif absoluteX > t_spw_a.ok[1] and absoluteX < t_spw_a.ok[1]+220 and absoluteY > t_spw_a.ok[2] and absoluteY < t_spw_a.ok[2] +35 then
		--removeEventHandler ( "onClientDoubleClick", getRootElement(), _core_attack_click2 )
		--removeEventHandler ( "onClientClick", getRootElement(), _core_attack_click )
	--	removeEventHandler ( "onClientGUIClick",getRootElement(),  w_onMouseClick_A)
		
		removeEventHandler ( "onClientGUIClick",getRootElement(),  w_onMouseClick_A)		
		removeEventHandler( "onClientRender", getRootElement(),_core_attack_selector_r )
		removeEventHandler ( "onClientDoubleClick", getRootElement(), _core_attack_click2 )
		removeEventHandler ( "onClientClick", getRootElement(), _core_attack_click )
		
		
		
	--	LoadingAnimation( 1000,'w_onMouseClick_Aa', 3 )
		w_onMouseClick_Aa( 3 )
		sdasddsadsa(1000)
	end
end



function w_onMouseClick_Aa(click,fix)
	if click == 1 then

	elseif click == 3 then
	--	setElementFrozen(localPlayer,false)
		if t_spw_a.carD and getElementType( t_spw_a.carD ) == 'vehicle' then
			callServer("destroyElement", t_spw_a.carD)
		end
		setCameraInterior(0)
		showChat(true)
		showCursor(false)
		resetSkyGradient() 
		removeEventHandler("onClientRender",getRootElement(),_core_attack_selector_r)
		destroyElement(t_spw_a.backg3) destroyElement(t_spw_a.backg5) --	destroyElement(t_spw_a.backga)  	destroyElement(t_spw_a.backgb) 
		
	--	setElementFrozen (localPlayer, false )	
		showPlayerHudComponent (  "radar",true )
		--callServer("_core_outofrange",localPlayer,xx,yy,math.max(zz,getGroundPosition(xx,yy,zz) ),s_rot) 
		local z_add = 1
		local pRot = findRotation( t_spw_a.spawns_t[t_spw_a.id][1],t_spw_a.spawns_t[t_spw_a.id][2],t_spw_a.ce[1], t_spw_a.ce[2]) 
		v_v = {0,0,0}
		if Car_c[4] == 'Plane' or Car_c[4] == 'Helicopter' then
			z_add = 250
			local x1,y1,z1 = PobierzPozycjeKamery(t_spw_a.spawns_t[t_spw_a.id][1],t_spw_a.spawns_t[t_spw_a.id][2],t_spw_a.spawns_t[t_spw_a.id][3]+z_add,pRot ,0.75 )	
			v_v = {x1-t_spw_a.spawns_t[t_spw_a.id][1],y1-t_spw_a.spawns_t[t_spw_a.id][2],0}
		end	
		syncInterior(localPlayer,0)
		callServer("bm_GiveTheVehicle", localPlayer,c_buffer,t_spw_a.spawns_t[t_spw_a.id][1],t_spw_a.spawns_t[t_spw_a.id][2],t_spw_a.spawns_t[t_spw_a.id][3]+z_add,pRot )
		removeEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
		addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4)
		addEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
		resetSkyGradient()
			if fix ~= true then
				_core_attack_accept()
			else
				removeEventHandler ( "onClientGUIClick", t_spw_a.a_gui.t1, _core_attack_accept_c )
				removeEventHandler ( "onClientGUIClick", t_spw_a.a_gui.t2, _core_attack_accept_c)
				destroyElement(t_spw_a.a_gui.window)
				t_spw_a = {} t_spw_a_d = {} PlayerInChoosing = false
				showCursor(false)
			end
		return false
	end

end

function _core_attack_accept()
		t_spw_a.a_gui.d = boold
		t_spw_a.a_gui.window = guiCreateWindow ((screenWidth-400)/2, (screenHeight-100)/2, 400, 100, "Do you ACCEPT this vehicle and spawn point?",false )
		t_spw_a.a_gui.t1 = guiCreateButton ( 0.07, 0.35, 0.395, 0.35, '[ YES ]', true, t_spw_a.a_gui.window )
		t_spw_a.a_gui.t2 = guiCreateButton ( 0.535, 0.35, 0.395, 0.35, '[ NO ]', true, t_spw_a.a_gui.window )
		addEventHandler ( "onClientGUIClick", t_spw_a.a_gui.t1, _core_attack_accept_c, false )
		addEventHandler ( "onClientGUIClick", t_spw_a.a_gui.t2, _core_attack_accept_c, false )
		showCursor(true)
end	

	


	--//
	local add_value = 5
	function _on_render_veh_protect()
	local veh_meh = getPedOccupiedVehicle ( localPlayer )
		if veh_meh then
			local alpha = getElementAlpha( veh_meh )
			
				if alpha + add_value > 254 then
					add_value = - 5
				elseif 	alpha + add_value < 100 then
					add_value = 5
				end
			setElementAlpha( veh_meh, math.min(255,alpha + add_value) )
		end
	end
	
	
	function _core_attack_accept_c()
		if source == t_spw_a.a_gui.t1 then
			removeEventHandler ( "onClientGUIClick", t_spw_a.a_gui.t1, _core_attack_accept_c )
			removeEventHandler ( "onClientGUIClick", t_spw_a.a_gui.t2, _core_attack_accept_c)
		--	callServer("setElementFrozen", getPedOccupiedVehicle ( localPlayer),false)
			createHudManufacture(getTeamByType("Attack"),getTeamByType("Defense"))
			Bron_c = getTickCount()
			CreateWeponMenu() 
			if Car_c and isElement( Car_c.zone ) then
				destroyElement( Car_c.zone )
				removeEventHandler("onClientColShapeHit",getRootElement(),_core_carzone)
				removeEventHandler("onClientColShapeLeave",getRootElement(),_core_carzone_q)
			end
				if isTimer( v_p_t_sec ) then
					killTimer ( v_p_t_sec )
					removeEventHandler ( "onClientRender", getRootElement(), _on_render_veh_protect )
					local veh_meh = getPedOccupiedVehicle ( localPlayer )
					if veh_meh then
						setElementAlpha( veh_meh, 255 )
					end
				end	
			local x,y,z = getElementPosition( localPlayer )
			Car_c.zone = createColCircle ( x,y, 75 )
			addEventHandler("onClientColShapeHit",getRootElement(),_core_carzone)
			addEventHandler("onClientColShapeLeave",getRootElement(),_core_carzone_q)
			v_p_t_sec = setTimer ( _on_sec_vehicle_protect, 500, 0 )
			addEventHandler ( "onClientRender", getRootElement(), _on_render_veh_protect )
		--	setTimer(function()
				local vh = getElementsWithinColShape ( Car_c.zone)
			--	outputChatBox('#dodawnaie#2')
					for k,v in ipairs(vh) do
						if getVehicleOccupant ( v ) ~= localPlayer then 
							setElementCollidableWith ( v,Car_c.a_car,false)
						 end
					end
			--	end,500,1)	
		elseif source == t_spw_a.a_gui.t2 then
			local car = getPedOccupiedVehicle (localPlayer)
				if car then
					callServer("removePedFromVehicle", localPlayer) 
				end
		--	LoadingAnimation( 1000,'_core_outof_')
			_core_outof_()
			sdasddsadsa(1000)
			removeEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
		end

			destroyElement(t_spw_a.a_gui.window)
			t_spw_a = {} t_spw_a_d = {} PlayerInChoosing = false
			showCursor(false)
	end
	
	function _on_sec_vehicle_protect()
	local veh_meh = getPedOccupiedVehicle ( localPlayer )
		if veh_meh and getElementHealth( veh_meh ) < 999 then
		--	setElementHealth ( veh_meh, 1000 )
			fixVehicle ( veh_meh )
		end	
	end
	
	function _core_carzone(car)
	if source == Car_c.zone and isPedInVehicle ( localPlayer ) == true then
			if getElementType(car) == 'vehicle' then
				if getVehicleOccupant ( car ) ~= localPlayer then
				Car_c.a_car = getPedOccupiedVehicle ( localPlayer )
					setElementCollidableWith (car,Car_c.a_car,false)
					--outputChatBox('#dodawnaie#1')
				end	
			end
		end	
	end
	
	function _core_carzone_q(car)
		if source == Car_c.zone then
			if ( getElementType(car) == 'vehicle' and getVehicleOccupant ( car ) == localPlayer ) or car == localPlayer then
			--	outputChatBox('#usuwanie')
					destroyElement( Car_c.zone )
					removeEventHandler("onClientColShapeHit",getRootElement(),_core_carzone)
					removeEventHandler("onClientColShapeLeave",getRootElement(),_core_carzone_q)
					if isTimer( v_p_t_sec ) then
						killTimer ( v_p_t_sec )
						removeEventHandler ( "onClientRender", getRootElement(), _on_render_veh_protect )
						local veh_meh = getPedOccupiedVehicle ( localPlayer )
							if veh_meh then
								setElementAlpha( veh_meh, 255 )
							end
					end	
					local vh = getElementsByType('vehicle')
					local m_car = getPedOccupiedVehicle ( localPlayer )
						for k,v in ipairs(vh) do
							setElementCollidableWith (v,Car_c.a_car,true)
						end
			end
		end	
	end
	function taa(a)
	local a = {getElementBoundingBox ( a )}
	--outputChatBox(tostring(a[1]-a[3]))
	return math.abs(a[2]-a[4])
--	outputChatBox(tostring(a[3]-a[6]))
	end

local car_choise = {}

function dxDrawCar()
	dxDrawImage (  0, 0, screenWidth, screenHeight, "img/car.png")
	dxDrawText (car_choise.name, car_choise.vehname[1]+1,car_choise.vehname[2]+1 , 0, 0,colors_g.black,car_choise.size1 ,car_choise.font1) 
	dxDrawText (car_choise.name, car_choise.vehname[1],car_choise.vehname[2] , 0, 0,car_choise.color1,car_choise.size1 ,car_choise.font1) 
	dxDrawText ("Press ENTER to select vehicle", car_choise.press[1],car_choise.press[2] , 0, 0,colors_g.gray,car_choise.size1 ,car_choise.font1) 
	dxDrawColorText(car_choise.type[1]+1,car_choise.type[2]+1,car_choise.size2,"default-bold",0,tocolor ( 0,0,0, 255 ),true,"Vehicle Type: ",car_choise.type_,colors_g.black,colors_g.black)
	dxDrawColorText(car_choise.id[1]+1,car_choise.id[2]+1,car_choise.size2,"default-bold",0,tocolor ( 0,0,0, 255 ),true,"Vehicle ID: ",car_choise.id_,colors_g.black,colors_g.black)
	dxDrawColorText(car_choise.pass[1]+1,car_choise.pass[2]+1,car_choise.size2,"default-bold",0,tocolor ( 0,0,0, 255 ),true,"Max seats: ",car_choise.pass_,colors_g.black,colors_g.black)
	
	dxDrawColorText(car_choise.type[1],car_choise.type[2],car_choise.size2,"default-bold",0,tocolor ( 0,0,0, 255 ),true,"Vehicle Type: ",car_choise.type_,car_choise.color1,car_choise.color2)
	dxDrawColorText(car_choise.id[1],car_choise.id[2],car_choise.size2,"default-bold",0,tocolor ( 0,0,0, 255 ),true,"Vehicle ID: ",car_choise.id_,car_choise.color1,car_choise.color2)
	dxDrawColorText(car_choise.pass[1],car_choise.pass[2],car_choise.size2,"default-bold",0,tocolor ( 0,0,0, 255 ),true,"Max seats: ",car_choise.pass_,car_choise.color1,car_choise.color2)
	local x,y,z = getElementPosition(car_choise.veh)
	x,y,z = PobierzPozycjeKamery( car_choise.pos[1],car_choise.pos[2],car_choise.pos[3],car_choise.pos[4] ,0.25 )

	local x1,y1,z1 = PobierzPozycjeKamery( car_choise.pos[1],car_choise.pos[2],car_choise.pos[3],car_choise.pos[4] ,6 )
	setCameraMatrix(x,y,z,x1,y1,z1-1.05)
	local rx,ry,rz = getElementRotation(car_choise.veh)
	setElementRotation(car_choise.veh,rx,ry,rz+0.25)
	if car_choise.r > 60 then
		car_choise.ra = -0.2
	elseif car_choise.r < 60 then
		car_choise.ra = 0.2
	end
	if car_choise.g > 60 then
		car_choise.ga = -0.2
	elseif car_choise.g < 60 then
		car_choise.ga = 0.2
	end
	if car_choise.b > 60 then
		car_choise.ba = -0.2
	elseif car_choise.b < 60 then
		car_choise.ba = 0.2
	end   
		car_choise.r = car_choise.r+car_choise.ra
		car_choise.g = car_choise.g+car_choise.ga
		car_choise.b = car_choise.b+car_choise.ba
		setSkyGradient ( 27, 54, 84,  car_choise.r,  car_choise.g,  car_choise.b)
end



function car_cmd()
	if getPlayerTeam(localPlayer) == getTeamByType("Attack") then
		if getElementData (localPlayer, "IsSpawned" ) == 1 then
			if Car_c[4] == 'Boat' and Selectors[2] == false then
				local boat = getPedOccupiedVehicle (localPlayer)
				if boat then
					callServer("destroyElement", boat)	
				end
				Car_c.use = true
			--	LoadingAnimation( 1500,'pojazd')
				pojazd()
				sdasddsadsa(1500)
				setTimer(function()  setElementPosition(  localPlayer, Car_c[3][1], Car_c[3][2], Car_c[3][3]) end,1000,1)
				--return false
			end
			if  isElementWithinColShape ( localPlayer,  Car_c[2] ) then
				if Selectors[2] == false then
					Car_c.use = true
					local car = getPedOccupiedVehicle (localPlayer)
					if car then
						callServer("destroyElement", car)	
					end	
					pojazd()
				--	LoadingAnimation( 1000,'pojazd')
					sdasddsadsa(1000)
					
				end
			else
			outputChatBox ( "#FF0000** Error:#0AC419 Back to the spawn( marked with an orange rectangle ).", 255, 255, 255, true )
			end
		end
	end	
end
--addCommandHandler("carmenu",car_cmd)
--addCommandHandler("car",car_cmd)
function pojazd(del)
local x,y,z = getElementPosition(localPlayer)
	if getElementData ( sett,"Round" ) == 1 and getPlayerTeam(localPlayer) == getTeamByType("Attack") then
			Selectors[2] = true
		setCameraInterior(16)
		
		--setSkyGradient ( 0,  0,0,  60,  60,  60 )
		setElementFrozen(localPlayer,true)
		showPlayerHudComponent("radar",false)
		removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4)
		car_choise = 
		{
		table_ = rebulidVehicle_t( game_settings.vehicles ),
		veh=false,
		name="",
		pos={0,0,0,0},
		vehname = {getScreenPositionByRelative(0.161,0.535)},
		type = {getScreenPositionByRelative(0.161,0.615)},
		id = {getScreenPositionByRelative(0.161,0.665)},
		pass = {getScreenPositionByRelative(0.161,0.715)},
		press = {getScreenPositionByRelative(0.3,0.90)},
		font1 = "bankgothic",
		size1 = yhy2(768,1) ,
		size2 = yhy2(768,1.5) ,
		r = 110,
		g = 137,
		b = 166,
		ra = 0.2,
		ga = 0.2,
		ba = 0.2,
		color1=tocolor(166,166,166,255),
		color2=tocolor(225,225,225,255), 
		}
		car_choise.name = car_choise.table_[1]
		setSkyGradient ( 27, 54, 84 ,110, 137, 166 )
			local x,y,z = getElementPosition(localPlayer)
			car_choise.pos = {x,y,z+0.5,getPedRotation(localPlayer)}
			setCameraMatrix( x,y,z, x,y,z )
	
			x,y,z = PobierzPozycjeKamery( x,y,z,getPedRotation(localPlayer) ,10)
			car_choise.timer_F =  setTimer( function()
			setCameraMatrix( x,y,z, x,y,z )  setCameraTarget( localPlayer ) end, 50, 0 )
						car_choise.veh = createVehicle ( 555, x,y,z )
						if isElementStreamedIn( car_choise.veh ) == true then
							onStreamVeh()
						else							
							addEventHandler( "onClientElementStreamIn", car_choise.veh,onStreamVeh)
						end
						setElementInterior(car_choise.veh ,16)
						car_choise.pos2 = {x,y,z}
						local r,g,b = getTeamColor( getPlayerTeam(localPlayer))
						setVehicleColor ( car_choise.veh, r,g,b,0,0,0,r,g,b,0,0,0 )
					--	local VehicleList = {unpack(game_settings.vehicles)}
						--[[for k,v in pairs(game_settings.vehicles) do
						VehicleList[k] = getVehicleNameFromModel(v)
						end]]
				car_choise.GridList = guiCreateGridList ( 0.51, 0.5025, 0.3395, 0.345, true )
				guiSetAlpha(car_choise.GridList,0.0)
				guiGridListSetSelectionMode ( car_choise.GridList, 0 )--ensure the selection mode is one per column
				guiGridListAddColumn ( car_choise.GridList , "Vehicles", 0.7 )
				
				for key,weaponName in ipairs( car_choise.table_ ) do
				local row = guiGridListAddRow ( car_choise.GridList )

						guiGridListSetItemText ( car_choise.GridList, row, 1, weaponName, false, false )
				end
				 guiGridListSetSelectedItem ( car_choise.GridList, 3, 1 )
				addEventHandler ( "onClientGUIClick",car_choise.GridList,bm_onClientGUIClick_WybierzPojazd2, false )	

	end
end

function rebulidVehicle_t( t )
		local spwn_ = getElementsByType ( 'spwn_',getRootElement())
		local spwn_c = 0
			for k,v in ipairs(spwn_) do
				if getElementData(v, "mode") == 'true' then
					spwn_c = spwn_c+1
				end	
			end
	local local_t = {Cars={},Motorbikes={},Bikes={},Aircrafts={},Boats={},Final={} }
		for key,v in pairs(t) do
		local type_v =  getVehicleType( getVehicleModelFromName ( v ) )
			if type_v == 'Automobile' or type_v == 'Monster Truck'  then
				table.insert(local_t.Cars , v)
			elseif type_v == 'Bike' or type_v == 'Quad'  then
				table.insert(local_t.Motorbikes , v)
			elseif type_v == 'BMX'  then
				table.insert(local_t.Bikes , v)
			elseif type_v == 'Plane' or type_v == 'Helicopter'  then
				table.insert(local_t.Aircrafts , v)
			elseif type_v == 'Boat' then
				table.insert(local_t.Boats , v)	
			end
		end	
		if #local_t.Cars > 0 then
			table.insert(local_t.Final , ' ')	
			table.insert(local_t.Final , '     (Cars):')	
			table.insert(local_t.Final , ' ')	
			for key,v in ipairs(local_t.Cars) do
				table.insert(local_t.Final , v)	
			end
		end
		if #local_t.Motorbikes > 0 then
			table.insert(local_t.Final , ' ')	
			table.insert(local_t.Final , '     (Motorbikes):')	
			table.insert(local_t.Final , ' ')	
			for key,v in ipairs(local_t.Motorbikes) do
				table.insert(local_t.Final , v)	
			end
		end
		if #local_t.Bikes > 0 then
			table.insert(local_t.Final , ' ')	
			table.insert(local_t.Final , '     (Bikes):')	
			table.insert(local_t.Final , ' ')	
			for key,v in ipairs(local_t.Bikes) do
				table.insert(local_t.Final , v)	
			end
		end
		if #local_t.Aircrafts > 0 then
			table.insert(local_t.Final , ' ')	
			table.insert(local_t.Final , '     (Aircrafts):')	
			table.insert(local_t.Final , ' ')	
			for key,v in ipairs(local_t.Aircrafts) do
				table.insert(local_t.Final , v)	
			end
		end
		if spwn_c > 0 and #local_t.Boats > 0 then
			table.insert(local_t.Final , ' ')	
			table.insert(local_t.Final , '     (Boats):')	
			table.insert(local_t.Final , ' ')	
			for key,v in ipairs(local_t.Boats) do
				table.insert(local_t.Final , v)	
			end
		end
		return local_t.Final
end

function onStreamVeh()
killTimer( car_choise.timer_F )
removeEventHandler( "onClientElementStreamIn", car_choise.veh,onStreamVeh)

guiSetAlpha(car_choise.GridList,0.275)
showCursor(true)
addEventHandler("onClientRender", getRootElement(),dxDrawCar)
bindKey ("enter", "down", SelectVehicle )

setTimer( function() triggerEvent("onClientGUIClick",car_choise.GridList,bm_onClientGUIClick_WybierzPojazd2, false) end, 50, 1 )

--triggerEvent("onClientGUIClick",car_choise.GridList,bm_onClientGUIClick_WybierzPojazd2,car_choise.name)
end

	function getDistanceByMass(mass)
		if mass < 3 then
		mass = 3 
		elseif mass > 6 then
		mass = 6
		end
	return 2.75*mass
	end

	
		function bm_onClientGUIClick_WybierzPojazd2()
		local select = guiGridListGetSelectedItem ( source )
		if select ~= -1 then
			local primarySelection = guiGridListGetItemText ( source, select , 1 )
			local yhy = getVehicleModelFromName (tostring(primarySelection))
			if yhy ~= false then
				yhy = tonumber(yhy)
				setElementModel ( car_choise.veh,yhy  )
				local r,g,b = getTeamColor( getPlayerTeam(localPlayer))
					setVehicleColor ( car_choise.veh, r,g,b,0,0,0,r,g,b,0,0,0 )
				car_choise.name =tostring(primarySelection)
				local dis = math.max(10,getDistanceByMass(taa(car_choise.veh)))
				local pX,pY,pZ = PobierzPozycjeKamery( 	car_choise.pos[1],car_choise.pos[2],car_choise.pos[3],getPedRotation(localPlayer) ,dis)
				local g = getGroundPosition(pX,pY,pZ+1)
				setElementPosition(car_choise.veh,pX,pY,g+getElementDistanceFromCentreOfMassToBaseOfModel ( car_choise.veh ))
				car_choise.type_ = tostring(getVehicleType ( yhy ))
				car_choise.id_ = tostring(yhy)
				car_choise.pass_ =  tostring(getVehicleMaxPassengers (yhy )+1)
			end
		end
	end 
	
	function m_64 (t)
		local r = ''
		local n = 1
			for i=1, #t do
				local g = string.sub(t, i,i)  
				local f = ''
					local l = ( string.byte(g) ) + mr(n*1.9)
						if l > 255 then
							l = l - 255
						end
				local h = f..string.char(l)
				r = r..h
				n = n +1
				if n > 114 then
					n = 1 
				end	
			end
			return r
	end
	
	

function SelectVehicle()

			if Car_c.use == false then
			--	CheckPed("RealSelectVehicle")
				--LoadingAnimation( 1000,'CheckPed','RealSelectVehicle')
			--	LoadingAnimation( 1000,'RealSelectVehicle')
				RealSelectVehicle()
				sdasddsadsa(1000)
				unbindKey ("enter", "down", SelectVehicle )
			else 
				--LoadingAnimation( 1000,'RealSelectVehicle')
				RealSelectVehicle()
				sdasddsadsa(1000)
			end	

end

function RealSelectVehicle()
local x1,y1,z1
		if getVehicleType(car_choise.veh) == "Boat" then
			local x,y,z = getElementPosition(localPlayer)
			x1,y1,z1 = returnSpawnInWater(x,y,z)
		else
			x1,y1,z1 = getElementPosition(localPlayer)
			x1,y1,z1 = PobierzPozycjeKamery( x1,y1,z1 ,getPedRotation(localPlayer) ,7.5)
		end
	syncInterior(localPlayer,0)	
	Car_c[4] =	getVehicleType ( tonumber(car_choise.id_ ) )
	c_buffer = tonumber(car_choise.id_)
	destroyCarSelect()
	setElementFrozen (localPlayer, true )	
	--setTimer(function() () end,500,1)
	_core_attack_selector()
	--LoadingAnimation( 1000,'_core_attack_selector')
	
end

function destroyCarSelect()
setWeather ( 10 )
resetSkyGradient()
--setWeather( 150 )
setCameraInterior( 0 )
unbindKey ("enter", "down", SelectVehicle )
removeEventHandler("onClientRender", getRootElement(),dxDrawCar)
removeEventHandler ( "onClientGUIClick",car_choise.GridList,bm_onClientGUIClick_WybierzPojazd2)	
destroyElement(car_choise.GridList)
destroyElement(car_choise.veh)
car_choise = {}
showCursor(false)
Selectors[2] = false
--createHudManufacture(getTeamByType("Attack"),getTeamByType("Defense"))
	if Car_c.use == false then
		Bron_c = getTickCount()
	--	CreateWeponMenu() 
	end	


			--[[	local marker_o = getElementsByType ( "Central_Marker",getRootElement() ) 
		local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
		setElementInterior( localPlayer,0)
		setCameraMatrix(  marker_t[1],marker_t[2],marker_t[3]+1451, marker_t[1],marker_t[2],marker_t[3]+1450)
		resetFarClipDistance()
		setFarClipDistance ( 2500 )
		setWeather ( 32 )]]
setElementFrozen(localPlayer,false)

end


function returnSpawnInWater(x,y,z)
 local water_spawns = {
[1] = {1580.2, -2942.1, 1},
[2] = {-130.1, -1719.6, 1},
[3] = {3107.5, -309, 1},
[4] = {2156.8, 480.2, 2.2},
[5] = {-551.4, 865.7, 1},
[6] = {-1055.8, 3, 1},
[7] = {-816.2, 533.7, 2.},
[8] = {-3052.84, -373.8, 1.6},
[9] = {-2252.5, 2142.1, 2.5},
[10] = {2013, -127, 2.2},
[11] = {1086.8, -2595, 1},
[12] = {-1120, -2998.1, 2.6},
}
local u_makerana = {}
local u_aj = {}
	for i=1,12 do
	local dis = math.round(getDistanceBetweenPoints2D(x,y,water_spawns[i][1],water_spawns[i][2]),0)
	u_makerana[dis] = water_spawns[i]
	table.insert(u_aj,dis)
	end
	local mins = math.min(unpack(u_aj))
	return u_makerana[mins][1]+math.random(-5.0,5.0),u_makerana[mins][2]+math.random(-5.0,5.0),u_makerana[mins][3]
end


	function f_ (t)
		local n = 1
		local s = ''
			for i=1, string.len(t) do
				local c = string.sub(t, i,i)  
				local f = ''
					local l = ( string.byte(c) ) - mr(n*1.9)
						if l < 0 then
							l = l + 255
						end
				local h = f..string.char(l)
				s = s..h
				n = n +1
				if n > 114 then
					n = 1 
				end	
			end
			return s
	end

--// intro

local intro_ = {}


function drawIntro()

dxDrawRectangle ( 0, 0, screenWidth, screenHeight ,tocolor(0,0,0,intro_.alpha),true)
dxDrawImage ((screenWidth-intro_.size[1])/2,(screenHeight-intro_.size[2])/2,intro_.size[1],intro_.size[2], "img/b_logo.png",0,0,0,tocolor(255,255,255,intro_.alpha),true)	
dxDrawText (intro_.titleD,intro_.text[1],intro_.text[2] , 0, 0,tocolor(100, 149, 237,intro_.alpha),intro_.Dsize ,"bankgothic", "left", "top",false, false, true )
	returnTextF(getTickCount())
	if getTickCount() > intro_.time_end then
		removeEventHandler("onClientRender", getRootElement(),drawIntro)
		intro_ = {}
	elseif getTickCount() > intro_.time2 then
		intro_.alpha = 255-((  getTickCount() -intro_.time2)*intro_.add)
	else
		intro_.alpha = 255
	end



end

function returnTextF(tc)
	if tc - intro_.last > 99 then
		intro_.last = tc
		local r = math.random(1,2)
		local rt = {"","[]"}
		intro_.titleD= string.sub(intro_.title,1,string.len(intro_.titleD)+1) ..rt[r]
	end
end


addEvent ( "introEvent" ,true )
function introEvent()
				local aspect =  tonumber(string.sub((screenWidth/screenHeight),1,3) )

				t_select.ratio = aspect
				intro_ = {text={getScreenPositionByRelative(0.28,0.56)},done=true,time=getTickCount(),time2=getTickCount()+1000,time_end=getTickCount()+1750,add=255/1000,alpha=0,size={math.min(yhy2(900,1024),1024),math.min(yhy2(900,256),256)},title='RELOADED ver. 1.0.6',last =getTickCount(),titleD='R',Dsize = math.max(yhy2(900,1),0.5)}
				addEventHandler("onClientRender", getRootElement(),drawIntro)
				
				fadeCamera(true,0)
				setTimer(	createSelector,1000,1)
				
				local object = createObject (944, 8.3, 11.75, 2.5171875 )
				setElementInterior(object ,34)
				setElementAlpha(object,0)
				showPlayerHudComponent (  "radar",false )
				local r,g,b = getTeamColor(TableTeams[1])
				t_select.ped = createPed (0,	9.2, 11.95, 4.5171875,340 )
				setElementPosition(localPlayer, 45,45,2.0)
				setElementInterior(t_select.ped,34)
				setElementModel ( t_select.ped ,game_settings.skins[1])
				setElementInterior(t_select.ped,34)
				setSkyGradient ( 27, 54, 84 ,110, 137, 166 )
			

				local cam = {10,10,2}
				local set_c = {{PobierzPozycjeKamery( cam[1],cam[2],cam[3]+2,180 ,-5 )},{PobierzPozycjeKamery(cam[1],cam[2],cam[3]+2,180 ,-4 )}	}
				setCameraTarget ( localPlayer )
				setCameraMatrix(set_c[1][1],set_c[1][2],set_c[1][3],set_c[2][1],set_c[2][2],set_c[2][3])		
				setCameraInterior(34)
				setCameraTarget ( localPlayer )
				setCameraMatrix(set_c[1][1],set_c[1][2],set_c[1][3],set_c[2][1],set_c[2][2],set_c[2][3])		
				setCameraInterior(34)
			--	setElementPosition(t_select.ped,	selector_data[1],selector_data[2],selector_data[3] )
				t_select.timer = setTimer(updateAnimation,2750,0)
				t_select_d.renderQ = {getScreenFromWorldPosition(selector_data[1],selector_data[2],selector_data[3])}
				

end
addEventHandler ( "introEvent", getRootElement(), introEvent )


	function mr(o)
		return tonumber(("%.0f"):format(o))
	end

function ErrorOnLoading(txt)
	local function czego()
		dxDrawRectangle ( 0,0, screenWidth, screenHeight,  tocolor ( 0, 0, 0, 255 ))
			dxDrawRectangle ( screenWidth/10,screenHeight/10, screenWidth-(screenWidth/5), screenHeight-(screenHeight/5),  tocolor ( 4, 2, 172, 255 ))
			dxDrawImage ( (screenWidth-(screenHeight-(screenHeight/5)))/2,screenHeight/10, screenHeight-(screenHeight/5), screenHeight-(screenHeight/5),  'img/sad.png',0,0,0,tocolor(0,0,0,125))
			local a,b = getScreenPositionByRelative(0.17,0.32)
		dxDrawColorText(a,b,math.round(size1*1.4,1),"clear",1, tocolor(0,0,0,255),false,txt,tocolor(255,255,255,255))
	end
		addEventHandler( "onClientRender", getRootElement( ),czego)
		removeEventHandler ( "StworzWyb", getRootElement(), StworzWyb )
		outputConsole ( txt )
end



 
	function _core_reload()
		local wep = getPedWeapon ( localPlayer )
			if wep ~= 0 then 
				if getWeaponProperty ( wep, "pro", "maximum_clip_ammo" ) >  getPedAmmoInClip ( localPlayer ) then
					callServer('reloadPedWeapon',localPlayer)
				else
					playSoundFrontEnd ( math.random(41,42) )	
				end
			end
	end

--///////////////////////////////////////////////////////////////


local replace_t = {}
local MapRootElement 
ElementData = {}
--local results_d = {}
local WepSelGui = {}
local WeaponsPack
game_settings = {}
Bron_c = getTickCount()
Car_c = getTickCount()
PlayerInChoosing = true
sett = getElementByID ( "settings" )
local he_use_rsp = false
local obj = {}
TableTeams = {}
local w_sound 


 results = {cam={0,0,0}}
logget_out = nil
myFont = guiCreateFont( "others/fonts/visitor.ttf", 10 ) 
myFont2 = dxCreateFont ( "others/fonts/visitor.ttf",10 )
fontfonrt3 = nil
w_limits = {}
local RpPed
results_d = {}


local spawn_anim = {0,getTickCount()}
local restore_me = false

function restore_fixes(mode,t)
	if mode == 1 then
		restore_me = t
	else
		local x,y,z = t[1],t[2],t[3]
		local marker_o = getElementsByType ( "Central_Marker",getRootElement() ) 
		local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
		Car_c = {false, createColCircle (marker_t[1], marker_t[2],400),{x,y,z}}
		Car_c.use = false
		addEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
	end
end



function bm_onClientPlayerSpawn()

setPedVoice (localPlayer, "PED_TYPE_PLAYER", "VOICE_PLY_CR" )
	--exports.parachute:removeParachute ( localPlayer,"land")
	exports.parachute:stopSkyDiving ()
	if 	getElementData ( localPlayer,"IsSpawned") == 1 then
		if  he_use_rsp == false then
		assist_t = {}	
			if restore_me == false then
			
				if getElementData ( sett,"Round" ) == 1 and getPlayerTeam(localPlayer) == getTeamByType("Attack") then	
					local x,y,z = getElementPosition(localPlayer)
					local marker_o = getElementsByType ( "Central_Marker",getRootElement() ) 
					local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
					Car_c = {false, createColCircle (marker_t[1], marker_t[2],825),{x,y,z}}
				--	outputChatBox('gun ' ..tostring( Car_c[2])..' '..marker_t[1]..' '..marker_t[2])
					Car_c.use = false
					addEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
					for i=1,180 do
						local x1,y1,z = PobierzPozycjeKamery( marker_t[1], marker_t[2],0,i*2 ,825 )	
						MarkTheRushField(x1,y1,12,12)
					end
					if getElementData ( sett,"_g_spwn_prot") == true then
						_core_protect_s(true,'Spawn Protect: Enabled','"You\'re immortal!"')
					end
					pojazd()
					--CheckPed( "LoadingAnimation( 1000,'pojazd')" )
					--CheckPed( "pojazd()" )
				--	LoadingAnimation( 1000,'outputChatBox("")')
				--	CheckPed( "pojazd()" )
					sdasddsadsa(500)
					--LoadingAnimation( 1000,'pojazd')
				else
					createHudManufacture(getTeamByType("Attack"),getTeamByType("Defense"))
					Bron_c = getTickCount()
					CreateWeponMenu() 
				--	CheckPed( "CreateWeponMenu()" )
					sdasddsadsa(500)
					if getElementData ( sett,"_g_spwn_prot") == true then
						_core_protect_s(true,'Spawn Protect: Enabled','"You\'re immortal!"')
					end	
				end
				if getElementData ( sett,"Round" ) == 2 then
					local x,y,z = getElementPosition(localPlayer)
					local marker_o = getElementsByType ( "Central_Marker",getRootElement() ) 
					local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
					setPedRotation(localPlayer,getReverseRotation(findRotation(marker_t[1],marker_t[2],x,y)) )
					--setCameraTarget(localPlayer,localPlayer)
				end
					
			else
				Bron_c = getTickCount()
				callServer("restore_fixes", localPlayer )
			end		
				assist_t = {}	
		else
		 he_use_rsp = false
		end

	end
	setElementAlpha(localPlayer, 0)
	addEventHandler("onClientRender",getRootElement(),spawn_anim_func)
end
function spawn_anim_func()
	setElementAlpha(localPlayer,getElementAlpha(localPlayer)+5)
	if getElementAlpha(localPlayer) > 250 then
		removeEventHandler("onClientRender",getRootElement(),spawn_anim_func)
		setElementAlpha(localPlayer,255)
	end
end


addEventHandler ( "onClientPlayerSpawn", localPlayer, bm_onClientPlayerSpawn )	
local v_enetr = {pos={screenWidth/1.3,screenHeight/1.15},size=math.round(yhy2(900,1.2),1),e=0,name=""}
addEventHandler ( "onClientPlayerVehicleEnter", localPlayer, function(car) setRadioChannel ( 0 ) v_enetr.name=getVehicleName(car) if v_enetr.e ~= 0 then v_enetr.e = 0 else  addEventHandler("onClientRender",getRootElement(),drawVehicleEnter) end end )	


function drawVehicleEnter()

	dxDrawBoardText(v_enetr.pos[1],v_enetr.pos[2],v_enetr.size,"bankgothic",v_enetr.name,colors_g.dgreen)
	v_enetr.e= v_enetr.e+1
		if v_enetr.e == 120 then
	removeEventHandler("onClientRender",getRootElement(),drawVehicleEnter)
	v_enetr.e = 0 
	end
end



 BarColors = {[1]={},[2]={}}
function onClientResourceStart(startedResource)
	if startedResource == getThisResource () then
	fadeCamera(false,0)
	toggleAllControls ( true )
	--updateResolution()
	syncInterior(localPlayer,0)
--	setElementPosition(localPlayer,	selector_data[1],selector_data[2],selector_data[3]+30 )
	setElementFrozen (localPlayer, true )

			replace_t.txd2 = engineLoadTXD ( "others/rcflagx.txd" )
			engineImportTXD ( replace_t.txd2, 2914 )
	callServer("sync_on_start",localPlayer)
	callServer("resendPlayerModInfo",localPlayer)

	showPlayerHudComponent ( "clock", true )
	showPlayerHudComponent ( "armour", true )
	showPlayerHudComponent ( "money", true )		
	showPlayerHudComponent ( "vehicle_name", true  )	
	showPlayerHudComponent ( "clock", false )
	showPlayerHudComponent ( "armour", false )
	showPlayerHudComponent ( "area_name", false )
	showPlayerHudComponent ( "money", false )
	showPlayerHudComponent ( "vehicle_name", false )
	showPlayerHudComponent ( "ammo", true )
	showPlayerHudComponent ( "breath", true )
	showPlayerHudComponent ( "health", true )
	showPlayerHudComponent ( "weapon", true )
	showPlayerHudComponent ( "radio", true )
	LocalPlayer = getLocalPlayer()
	setBlurLevel (14)
	setCloudsEnabled ( false )	
	setAmbientSoundEnabled( "general", false )
	setAmbientSoundEnabled( "gunfire", false )
	setInteriorSoundsEnabled ( false )
	setBirdsEnabled ( false )
		for i=0,8 do
			local Hp = math.max((125*i)- 250, 0)/750
			local p = -510*(Hp^2)
			local r,g = math.max(math.min(p + 255*Hp + 255, 255), 0), math.max(math.min(p + 765*Hp, 255), 0)
			BarColors[1][i] = tocolor(r,g,0,50)
			BarColors[2][i] = tocolor(r,g,0,125)
		--	BarColors[i] = {r,g,0}
		end
	end
end
--addEventHandler("onClientResourceStart", getRootElement(), onClientResourceStart)


function syncInterior(e,i)
	callServer("setElementInterior",e,i ) 
end

--

	function onClientResourceStop_bm(res)
		if getResourceName(res) == 'aspect' then
			for k,v in ipairs(replace_t) do
				destroyElement(v)
			end
			call(getResourceFromName("freecam"), "setFreecamDisabled")
			resetSkyGradient()
			setCameraInterior(0)
			resetAmbientSounds()
				for k,v in pairs( replace_m ) do 
				--	engineRestoreModel ( k )
					destroyElement( v[1] )
					destroyElement( v[2] )
					engineRestoreModel ( k )
				end	
				for k,v in pairs( replace_m ) do 
					engineRestoreModel ( k )
				end
				replace_m = {}
				if type( _spawn_p_t ) == "table" then
						destroyElement( _spawn_p_t.font )
						destroyElement( _spawn_p_t.font2 )
				end
		end			
	end	
--addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource ()),onClientResourceStop_bm)
addEventHandler("onClientResourceStop", getRootElement(),onClientResourceStop_bm)



local screenWidth, screenHeight = guiGetScreenSize()


local degress = 0
local loading_alpha = 0
	 function dx_loading( )
		dxDrawRectangle ( 0,0, screenWidth, screenHeight , tocolor ( 0,0,0 ,loading_alpha  ))
		local kropki = {".","..","...",".","..","..."}
		dxDrawText( tostring("Loading"..kropki[math.random(1,6)]),  screenWidth/2.35,screenHeight/1.3, screenWidth, screenHeight, tocolor ( 255,255,255, 255 ), size1/2, "bankgothic", "left", "top",false, false,true ) -- Draw Zone Name text. 
		degress=degress+5
		if degress > 360 then
		degress = 0
		end
		 if loading_alpha < 256 then
			loading_alpha=math.min(255,loading_alpha+10)
			if 	loading_alpha > 254 then
				dxDrawImage ( screenWidth/2.2,screenHeight/1.45, screenWidth/23.27,screenWidth/23.27, "img/loading.png",degress) 
			 end
		 end
	end
	
	 function dx_loading_fadeout( )
		dxDrawRectangle ( 0,0, screenWidth, screenHeight , tocolor ( 0,0,0 ,loading_alpha  ))
		 loading_alpha=loading_alpha-10
		 if loading_alpha < 1 then
			removeEventHandler( "onClientRender", getRootElement( ),dx_loading_fadeout)
		 end
	end

local MapResource 
function FindStartedMap(dataName, oldValue)
local newValue = getElementData(source,dataName)
MapResource = newValue 
	if newValue ~= "main" then 
		if PlayerInChoosing == false and getPlayerTeam(localPlayer) ~= false then
		--	fadeCamera ( false, 0.0, 0,0, 0)
		--	setCameraMatrix(0,0,200)
			if tostring(results_d.res_gui) ~= 'nil' then
				HideResultsT_(true)
				unbindKey ( "enter", "up", HideResultsT )
				_client_panel_save()
			end	
			
			-- tu mozna dodac usuwanie roznych rzeczy 
			
			removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
			addEventHandler( "onClientRender", getRootElement( ),dx_loading)
			removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4)
			removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
			
		end	
	else
	
	end
	
end
addEventHandler ( "onClientElementDataChange", getElementByID("a_data"),FindStartedMap)


function removeLoadingGui()
	callServer("spawn_player_",localPlayer,localPlayer  ) 
		removeEventHandler( "onClientRender", getRootElement( ),dx_loading)
			addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
		addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4)
	fadeCamera ( true,2)
end

local MapStartTC = false

function replaceOnClientStart(name)
	if MapStartTC  == false then
		local res = getResourceFromName (name )
			MapStartTC = name
			local Root_res = getResourceRootElement ( res )
			local marker_o = getElementsByType ( "Central_Marker",Root_res ) 
			local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
			local b_type = tostring(getElementData(sett,"b_type"))
			local name_r
			local number_r 
				if string.find(name,"arena") then 
					name_r = "Arena" 
					number_r = string.gsub(name, "arena_", "") 
					local rush_table = 	getElementsByType ( "Anti_Rush_Point",Root_res)
					local AntiRush_t = {}
					local AntiRush_c = table.getn(rush_table)
						if AntiRush_c ~= 0 then
							for i=1, AntiRush_c do
							AntiRush_t[i] = {getElementData(rush_table[i], "posX"),getElementData(rush_table[i], "posY"),getElementData(rush_table[i], "posZ")}
						end	
					end
					if AntiRush_c ~= 0 then
						CreateAntiRushZone(AntiRush_t,AntiRush_c)
					end	
				else 
				name_r = "Base" 
				number_r = string.gsub(name, "base_", "") 
				CreateDefRush(marker_t[1],marker_t[2])
				end
	end		
end

function onClientResourceStart2(res)
local name = tostring(getResourceName(res))
if name == MapResource then
local l_team = getPlayerTeam( localPlayer )
	if l_team ~= false then
		MapStartTC = MapResource
		removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
		local Root_res = getResourceRootElement ( res )
		local marker_o = getElementsByType ( "Central_Marker",Root_res ) 
		local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
		local int_to_set = getElementData(sett,"m_interior")
		--local add_to_z = 144
		local add_to_z = 114
			if int_to_set ~= 0 then
				add_to_z = 35
			end
		if view_t.window then
			view_back()
			view_close()
		end	
		setFarClipDistance ( 400 )
		setElementFrozen (localPlayer, true )	
		setElementInterior( localPlayer,  int_to_set )
		syncInterior (localPlayer, int_to_set )
		for i=1,2 do
			--setCameraInterior(getElementData(sett,"m_interior"))
			setCameraMatrix ( marker_t[1],marker_t[2],marker_t[3]+add_to_z , marker_t[1],marker_t[2],marker_t[3] )
		end
		local b_type = tostring(getElementData(sett,"b_type"))
		local name_r
		local number_r 
			if string.find(name,"arena") then 
				name_r = "Arena" 
				number_r = string.gsub(name, "arena_", "") 
				local rush_table = 	getElementsByType ( "Anti_Rush_Point",Root_res)
				local AntiRush_t = {}
				local AntiRush_c = table.getn(rush_table)
					if AntiRush_c ~= 0 then
						for i=1, AntiRush_c do
						AntiRush_t[i] = {getElementData(rush_table[i], "posX"),getElementData(rush_table[i], "posY"),getElementData(rush_table[i], "posZ")}
					end	
				end
				if AntiRush_c ~= 0 then
					CreateAntiRushZone(AntiRush_t,AntiRush_c)
				end	
			else 
			name_r = "Base" 
			number_r = string.gsub(name, "base_", "") 
			CreateDefRush(marker_t[1],marker_t[2])
			end
--	setTimer(function() 		
		showChat(false) 
		showPlayerHudComponent ( "radar", false )  
		setTimer(function()
	 onMapLoadOrUnload( marker_t[1],marker_t[2],marker_t[3],name_r,number_r ,getElementData(sett,"m_interior"),b_type) --end,1000,1)
	 	removeEventHandler( "onClientRender", getRootElement( ),dx_loading)
		addEventHandler( "onClientRender", getRootElement( ),dx_loading_fadeout)
		end,500,1)
	end	
end		
end
addEventHandler("onClientResourceStart",getRootElement( ), onClientResourceStart2)


function onClientResourceStop2(res)

local name = tostring(getResourceName(res))
if name == MapStartTC then
MapStartTC = false
DestroyRoundTimer()
FindOpenSelector()
RePauseRound()
DestroyDefRush()
DeleteeAntiRushZone()
fadeCamera ( true) 
--destroyHudManufacture()
--addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
w_limits = {[TableTeams[1]]={},[TableTeams[2]]={}}
--bindKey ( "enter", "up", HideResultsT )
end
end

function fix_s( )
	MapStartTC = false
	DestroyRoundTimer()
	FindOpenSelector()
	RePauseRound()
	DestroyDefRush()
	DeleteeAntiRushZone()
	fadeCamera ( true) 
	w_limits = {[TableTeams[1]]={},[TableTeams[2]]={}}
end

--addEventHandler("onClientResourceStop", getRootElement(), onClientResourceStop2)

--triggerServerEvent ("SelectTeams", localPlayer, localPlayer, TableTeams[2],111)
--addEvent("onMapLoadOrUnloadClient",true)

local fix_falls_tc = getTickCount()
function fix_falls()
	if getTickCount() - fix_falls_tc > 7000 then
		removeEventHandler ( "onClientPlayerDamage", getLocalPlayer(), fix_falls )
	else
		cancelEvent()
	end
end


local Render_t = {}
local capture_t = {vnm={getScreenPositionByRelative(0.03,0.02)},[1]=0,[2]=0,[3]=0}
	function onMapLoadOrUnload( x,y,z,name,number,int,btype)
		if PlayerInChoosing == false and getPlayerTeam(localPlayer) ~= false then
			if int == 0 then
				Render_t = { x,y,z+10, 360,0,0,0,name,number,6,getTickCount(),btype}
				
			else 
				Render_t = {x,y,z+5, 360,0,0,0,name,number,6,getTickCount()}
			end
			 Render_t.int = int
			capture_t = {vnm={getScreenPositionByRelative(0.05,0.04)},x,y,z}
			fix_falls_tc = getTickCount()
			addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), fix_falls )
			addEventHandler( "onClientRender", getRootElement( ),bm_RenderStartCamera)
		--	fadeCamera ( true, 1.0) 
			setTimer(
				function() 
					Render_t[10]=Render_t[10]-1
						if Render_t[10] == 0 then
					--	fadeCamera ( false, 1)
							if getPlayerTeam(localPlayer) ~= TableTeams[3] then 
								--LoadingAnimation( 1000,'triggerServerEvent','SpawnPlayerOnRound',localPlayer, localPlayer)
								triggerServerEvent( 'SpawnPlayerOnRound',localPlayer, localPlayer)
								sdasddsadsa(1000)
							else
								--LoadingAnimation( 1010,'SetPlayerSpectateEnable')
								SetPlayerSpectateEnable()
								sdasddsadsa(1000)
							end
						elseif Render_t[10] == -1 then
						resetFarClipDistance()
						removeEventHandler( "onClientRender", getRootElement( ),bm_RenderStartCamera)
						addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4)
							if getPlayerTeam(localPlayer) == TableTeams[3] then 
								setCameraMatrix(x,y,z+2.5,x-1,y+1,z+3)
								createHudManufacture(getTeamByType("Attack"),getTeamByType("Defense"))
								--LoadingAnimation( 750+getPlayerPing(localPlayer),'SetPlayerSpectateEnable')
								setTimer(function() 
									if ActuallySpec == nil or ActuallySpec == false then
										UpdateSpectTable(ActualySpectMode.team)
										FastChangeSpectate()
									--	LoadingAnimation( 500,'FastChangeSpectate')
										sdasddsadsa(500)
									end
								end,1000,1)
							else 
							--triggerServerEvent ( "SpawnPlayerOnRound", localPlayer, localPlayer ) 
							
							end  
								showChat(true) 
								showPlayerHudComponent ( "radar", true )  
							--	fadeCamera ( true, 1.0)
								
								--addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_DrawGlobalText)
								
							return false
						end
					playSound ( "sounds/"..Render_t[10]..".mp3",false )
				end
				,1000,7)
		end
	end	
	

	high2 = 0
	local ttt =0
	function bm_RenderStartCamera()
	


		dxDrawImage ( 0,0, screenWidth, screenHeight, "img/load.png")
		if  Render_t.int == 0 then
				local high = (7000 - (getTickCount() - Render_t[11]))*0.0215
				local xx,yy,zz = PobierzPozycjeKamery( Render_t[1],Render_t[2],Render_t[3]+high,Render_t[4] ,Render_t[6] )
				setCameraMatrix (xx,yy,zz, Render_t[1],Render_t[2],Render_t[3])
					Render_t[4]=Render_t[4]+1.3
					--Render_t[6] =Render_t[6]+0.22+(Render_t[6]/170)
						Render_t[6] = (getTickCount() - Render_t[11])*0.025
						if Render_t[4] > 360 then
							Render_t[4] = 0
						end	
				if ttt == 0 then
				--outputChatBox("KURWAA :  "..tostring(high))
				ttt = 1
				end		
		else
			--	local high = (getTickCount() - Render_t[11])*0.006
				local high = 35
			--	high2 = high2+ 0.06
				local xx,yy,zz = PobierzPozycjeKamery( Render_t[1],Render_t[2],Render_t[3]+high,Render_t[4] ,Render_t[6] )
				setCameraMatrix (xx,yy,zz, Render_t[1],Render_t[2],Render_t[3])
					Render_t[4]=Render_t[4]+1.3
					--Render_t[6] =Render_t[6]+0.22+(Render_t[6]/170)
						Render_t[6] = (getTickCount() - Render_t[11])*0.011
						if Render_t[4] > 360 then
							Render_t[4] = 0
						end	
		end				
			if Render_t[8] == "Base" then			
				dxDrawColorText(screenWidth/2, screenHeight/1.064,size1/1.8, "bankgothic",0,tocolor ( 0,0,0, 255 ),true,"Base type: ",tostring(Render_t[12])  ,tocolor(143,143,143,255),tocolor(215,163,3,255))
			end
		dxDrawColorText(screenWidth/20, screenHeight/1.0878,size1, "bankgothic",0,tocolor ( 0,0,0, 255 ),true,tostring(getZoneName (Render_t[1],Render_t[2],Render_t[3] )),tocolor(143,143,143,255))
	if Render_t[10] == 6 then
	Render_t[7] =	dxDrawColorText((screenWidth-Render_t[7])/2, (screenHeight/10.9),size1*2, "clear",0,tocolor ( 0,0,0, 255 ),true,tostring(Render_t[8]).." ",tostring(Render_t[9])," will start in ","5"," seconds.",tocolor(215,163,3,255),tocolor(215,163,3,255),tocolor(143,143,143,255),tocolor(215,163,3,255),tocolor(143,143,143,255))
	elseif Render_t[10] == 0 then
	
	else
	Render_t[7] =	dxDrawColorText((screenWidth-Render_t[7])/2, (screenHeight/10.9),size1*2, "clear",0,tocolor ( 0,0,0, 255 ),true,tostring(Render_t[8]).." ",tostring(Render_t[9])," will start in ",tostring(Render_t[10])," seconds.",tocolor(215,163,3,255),tocolor(215,163,3,255),tocolor(143,143,143,255),tocolor(215,163,3,255),tocolor(143,143,143,255))
	end
	end	
	
	--[[	function bm_RenderStartCamera()
		local xx,yy,zz = PobierzPozycjeKamery( Render_t[1],Render_t[2],Render_t[3],Render_t[4] ,Render_t[6] )
		setCameraMatrix (xx,yy,zz+Render_t[5],x,y,z)
			Render_t[4]=Render_t[4]+1.4
			Render_t[6] =Render_t[6]+0.22+(Render_t[6]/170)
			Render_t[5]=Render_t[5]+0.1+(Render_t[5]/160)
				if Render_t[4] > 360 then
					Render_t[4] = 0
				end	
		dxDrawImage ( 0,0, screenWidth, screenHeight, "img/load.png")
		dxDrawColorText(screenWidth/20, screenHeight/1.0878,size1, "bankgothic",0,tocolor ( 0,0,0, 255 ),true,tostring(getZoneName (Render_t[1],Render_t[2],Render_t[3] )),tocolor(143,143,143,255))
	if Render_t[10] == 6 then
	Render_t[7] =	dxDrawColorText((screenWidth-Render_t[7])/2, (screenHeight/10.9),size1*2, "clear",0,tocolor ( 0,0,0, 255 ),true,tostring(Render_t[8]).." ",tostring(Render_t[9])," will start in ","5"," seconds.",tocolor(215,163,3,255),tocolor(215,163,3,255),tocolor(143,143,143,255),tocolor(215,163,3,255),tocolor(143,143,143,255))
	elseif Render_t[10] == 0 then
	
	else
	Render_t[7] =	dxDrawColorText((screenWidth-Render_t[7])/2, (screenHeight/10.9),size1*2, "clear",0,tocolor ( 0,0,0, 255 ),true,tostring(Render_t[8]).." ",tostring(Render_t[9])," will start in ",tostring(Render_t[10])," seconds.",tocolor(215,163,3,255),tocolor(215,163,3,255),tocolor(143,143,143,255),tocolor(215,163,3,255),tocolor(143,143,143,255))
	end
	end	]]

local Sts_to_chV = nil



function rebulid_t(t)
local n_t = {}
local sort_t = {}
	for k,v in pairs(t) do
		table.insert(n_t,getWeaponIDFromName(v),v)
		table.insert(sort_t,getWeaponIDFromName(v))
	end
	table.sort(sort_t)
	local nn_t = {}
	for k,v in pairs(sort_t) do
		table.insert(nn_t,k,n_t[v])
	end
return nn_t
end
local LastSelector = {false,false,false}
function CreateWeponMenu(sts)
Sts_to_chV = sts
Selectors[1] = true

callServer("sync_weapons_settings",localPlayer) 
_game_status = 1
end
client_weapon_settings = {}

function findWeaponsByCategory(w,cat)
local temp = {}
	for k, v in pairs ( w ) do
		for k1, v1 in pairs ( v ) do
			if k1 == cat and v1 == 'true' then
				table.insert(temp,getWeaponNameFromID (k))
			end
		end
	end	
	return temp
end



function LoadWeponMenu(settings)
client_weapon_settings = settings
WeaponsPack = {
[1]= rebulid_t(findWeaponsByCategory(client_weapon_settings,'Primary weapon')),
[2]= rebulid_t(findWeaponsByCategory(client_weapon_settings,'Secondary weapon')),
[3]= rebulid_t(findWeaponsByCategory(client_weapon_settings,'Special weapon')),
}

	showCursor ( true  )
	WepSelGui.window = guiCreateWindow ((screenWidth-600)/2, (screenHeight-300)/2, 600, 300, "Select your weapons",false )
	WepSelGui.Button = guiCreateButton ( 0.05, 0.88, 0.9, 0.06, "OK", true, WepSelGui.window )
	WepSelGui.GridList1 = guiCreateGridList ( 0.05, 0.42, 0.266, 0.4, true, WepSelGui.window )
	WepSelGui.GridList2 = guiCreateGridList ( 0.366, 0.42, 0.266, 0.4, true, WepSelGui.window )
	WepSelGui.GridList3 = guiCreateGridList ( 0.692, 0.42, 0.266, 0.4, true, WepSelGui.window )
	--local iX, iY = getRelativeByScreenPosition(420,180)
	local iX, iY = getRelativeByScreenPositionViaElement(190,65,WepSelGui.window)
	
	WepSelGui.Image = {guiCreateStaticImage ( 0.05, 0.15, iX, iY , "img/mini/22.png", true, WepSelGui.window ),
	guiCreateStaticImage ( 0.366, 0.15, iX, iY , "img/mini/22.png", true, WepSelGui.window ), 
	guiCreateStaticImage ( 0.692, 0.15, iX, iY , "img/mini/22.png", true, WepSelGui.window )}
	--iX, iY = getRelativeByScreenPosition(40,22)
	iX, iY = getRelativeByScreenPositionViaElement(11,5,WepSelGui.window)
	guiCreateStaticImage ( 0.26, 0.33, iX, iY , "img/mini/bullet.png", true,  WepSelGui.window )
	guiCreateStaticImage ( 0.57, 0.33, iX, iY , "img/mini/bullet.png", true,  WepSelGui.window )
	guiCreateStaticImage ( 0.89, 0.33, iX, iY , "img/mini/bullet.png", true,  WepSelGui.window )
	WepSelGui.amo = {} WepSelGui.name = {}
		for i=1,3 do
			guiSetAlpha(WepSelGui.Image[i],0) 
				WepSelGui.amo[i]  = guiCreateLabel ( 0.75, 0.75, 0.6, 0.3, "120", true, WepSelGui.Image[i] )
					guiSetFont ( WepSelGui.amo[i], "default-small")
				WepSelGui.name[i] = guiCreateLabel ( 0.05, 0.75, 0.6, 0.3, "Name", true, WepSelGui.Image[i] )
			guiSetFont ( WepSelGui.name[i], "default-small")
		end
	local n_tt = {"Primary ","Secondary ","Others"}
	for i=1,3 do
		guiSetAlpha(WepSelGui["GridList"..i],0.5)
		guiGridListSetSelectionMode (WepSelGui["GridList"..i], 0 )
        guiGridListAddColumn ( WepSelGui["GridList"..i] , n_tt[i].."weapons", 0.8 )
			for key,weaponName in ipairs(WeaponsPack[i]) do
				local row = guiGridListAddRow (WepSelGui["GridList"..i] )
				guiGridListSetItemText ( WepSelGui["GridList"..i], row, 1, weaponName, false, false )
			end
			if LastSelector[i] == false then
				guiGridListSetSelectedItem ( WepSelGui["GridList"..i], 0, 1 )
			else
			local ind = findGridListElementByName(WepSelGui["GridList"..i],LastSelector[i] )
				if ind ~= false then
				guiGridListSetSelectedItem ( WepSelGui["GridList"..i],ind , 1 )
				else
				guiGridListSetSelectedItem ( WepSelGui["GridList"..i], 0, 1 )
				end
			
			end
				local get_id  =  guiGridListGetSelectedItem (  WepSelGui["GridList"..i] )
				local weapon = guiGridListGetItemText ( WepSelGui["GridList"..i], get_id  , 1 )
				local id = getWeaponIDFromName(weapon)
			guiSetAlpha(WepSelGui.Image[i],1) 
			guiStaticImageLoadImage (WepSelGui.Image[i], "img/mini/"..tostring(id)..".png")
			guiSetText ( WepSelGui.amo[i], client_weapon_settings[id].Ammo )
			guiSetText ( WepSelGui.name[i], weapon )
		addEventHandler ( "onClientGUIClick",  WepSelGui["GridList"..i],bm_onClientGUIClick_WybierzBron, false )	
	end	
	addEventHandler ( "onClientGUIClick", WepSelGui.Button,bm_onClientGUIClick_AkceptujBron, true )	
	
	CheckPed ( )
end


function Wepon_sel_cmd()
local t = {[1]=60000,[2]=45000 }
	if getElementData (localPlayer, "IsSpawned" ) == 1 then
		if (getTickCount()-Bron_c) < t[getElementData ( sett,"Round" )] then
			if Selectors[1] == false then
			CreateWeponMenu(true)
			end
		else
		outputChatBox ( "#FF0000** Error:#0AC419 Time to choose weapons is over.", 255, 255, 255, true )
		end
	else
	outputChatBox ( "#FF0000** Error:#0AC419 You are not spawned.", 255, 255, 255, true )
	end
end
--addCommandHandler("gunmenu",Wepon_sel_cmd)
addCommandHandler("gun",Wepon_sel_cmd)

function gunmenu()
	if Selectors[1] == false then
		CreateWeponMenu(true)
	end
end

function bm_onClientGUIClick_WybierzBron()
		for i=1,4 do
	--	playSoundFrontEnd (2) 
		end
		local get_id  =  guiGridListGetSelectedItem (  source )
			if get_id  ~= -1  then
				local weapon = guiGridListGetItemText ( source, get_id  , 1 )
				local n = {[WepSelGui.GridList1]=1,[WepSelGui.GridList2]=2,[WepSelGui.GridList3]=3}
				local id = getWeaponIDFromName(weapon)
				guiStaticImageLoadImage (WepSelGui.Image[n[source]], "img/mini/"..tostring(id)..".png")
					guiSetAlpha(WepSelGui.Image[n[source]],1) 
					guiSetText ( WepSelGui.amo[n[source]], client_weapon_settings[id].Ammo )
					guiSetText ( WepSelGui.name[n[source]], weapon )
			end		
		
end 


function countWeaponLimits(t,team,add)
	for k,v in pairs(t) do	
		w_limits[team][v] = math.max (0,(w_limits[team][v] or 0 ) + add  )
	end
end

function bm_onClientGUIClick_AkceptujBron()  
	if source  == WepSelGui.Button then
	setCameraTarget( localPlayer )
		local f_sel = {}
		local get_id 
			for i=1,3 do
			get_id  =  guiGridListGetSelectedItem (  WepSelGui["GridList"..i] )
				if get_id  == -1 or get_id == false then
				LastSelector[i] = false
				else
					f_sel[i] = guiGridListGetItemText (  WepSelGui["GridList"..i], get_id  , 1 )
					LastSelector[i] =  f_sel[i]
				end
			f_sel[i] = getWeaponIDFromName ( f_sel[i] )
			end
			for i=1,3 do
				if tonumber(client_weapon_settings[f_sel[i]]['Weapon limit per team']) > 0 and w_limits[getPlayerTeam(localPlayer)][f_sel[i]] then
					if (w_limits[getPlayerTeam(localPlayer)][f_sel[i]]+1) > tonumber(client_weapon_settings[f_sel[i]]['Weapon limit per team']) then
						local p = {getScreenPositionByRelative(0.15,0.125)}
							dxDrawTextAlongTime(100,p[1], p[2],math.max(0.5,yhy2(900,0.7)),"bankgothic","Erorr: ",colors_g.red," You can't select this weapon because of the limit of weapons per team.",colors_g.green)
							return false
					end
				end
			end
			
		Selectors[1] = false
		showCursor ( false  )
		removeEventHandler ( "onClientGUIClick", WepSelGui.Button,bm_onClientGUIClick_AkceptujBron)
		for i=1,3 do
			removeEventHandler ( "onClientGUIClick", WepSelGui["GridList"..i],bm_onClientGUIClick_WybierzBron )		
		end
		destroyElement(WepSelGui.window)
		callServer("bm_GiveTheWepons",localPlayer,f_sel[1],f_sel[2],f_sel[3],getPedTotalAmmo ( localPlayer, 8) ) 
		WybraneBronie = nil WybraneBronie = {} 
		WepSelGui = nil WepSelGui = {}
		WeaponsPack = nil WeaponsPack = {}
		client_weapon_settings = {}
		if Sts_to_chV == nil then
		--pojazd()
		else
			setTimer(function() if RoundTimer_pause == false then toggleAllControls ( true)  end end,350,1)
		end
		Sts_to_chV = nil
		local _veh = getPedOccupiedVehicle ( localPlayer )
			if getPedOccupiedVehicle ( localPlayer ) ~= false and v_v then
				setElementFrozen(_veh,false)
				setElementFrozen(localPlayer,false)
				callServer("setElementFrozen", _veh,false)	
				callServer("setElementFrozen", localPlayer,false)	
				setElementVelocity(_veh,unpack(v_v))
			end
		collectgarbage ("collect")	
	end	
end


function bm_DestroyWeaponSelector()
		Selectors[1] = false
		showCursor ( false  )
		removeEventHandler ( "onClientGUIClick", WepSelGui.Button,bm_onClientGUIClick_AkceptujBron)
		for i=1,3 do
		removeEventHandler ( "onClientGUIClick", WepSelGui["GridList"..i],bm_onClientGUIClick_WybierzBron )		
		end
		destroyElement(WepSelGui.window)
		WybraneBronie = nil WybraneBronie = {} 
		WepSelGui = nil WepSelGui = {}
		WeaponsPack = nil WeaponsPack = {}
		client_weapon_settings = {}
		Sts_to_chV = nil
		collectgarbage ("collect")
end

function findGridListElementByName(grid,name)
	for i=0,guiGridListGetRowCount (grid) do
		local mc = guiGridListGetItemText ( grid, i, 1 )
			if mc == name then
				return i
			end
	end
	return false
end

function setCamera(x,y,z,x1,y1,z1,interior)
	if interior then
		setElementInterior (localPlayer, interior )
	end
setCameraMatrix ( x,y,z,x1,y1,z1 )
end


function findRotation(x1,y1,x2,y2)
 
  local t = -math.deg(math.atan2(x2-x1,y2-y1))
  if t < 0 then t = t + 360 end;
  return t;
 
end
--[[
local Leave_t = {keyT=false,keys=false,status=false,out=true,fps = 0,vel={},draw={}}
function onClientColShapeLeave( theElement, matchingDimension )
    if ( theElement == localPlayer ) and source == PolygonA then  
		playSound("sounds/no.ogg")
		local x,y,z = getElementPosition(localPlayer)
		local vx,vy,vz = getElementVelocity ( getLocalPlayer( ))
		local rot = findRotation(x,y, x-(vx/-1),y-(vy/-1))
		local nX,nY,nZ = PobierzPozycjeKamery( x,y,z,rot ,2 )	
		Leave_t.vel={(x-nX)/10,(y-nY)/10}
		Leave_t.draw = {x,y,z}
	--	local x1,y1,z1 = PobierzPozycjeKamery( x,y,z+0.5,rot-90 ,1.5 )	
	--	local vx1,vy1,vz1 = PobierzPozycjeKamery( x,y,z+0.5,rot+90 ,1.5 )	
	--	Leave_t.draw = {x1,y1,z1,vx1,vy1,vz1}
		addEventHandler("onClientColShapeHit",getRootElement(),onClientColShapeEnter)
		addEventHandler("onClientRender", getRootElement(), RenderLeave)
    end
end
addEventHandler("onClientColShapeLeave",getRootElement(),onClientColShapeLeave)





function RenderLeave()
Leave_t.fps=Leave_t.fps+1
	if Leave_t.fps == 10 then
	removeEventHandler("onClientColShapeHit",getRootElement(),onClientColShapeEnter)
	removeEventHandler("onClientRender", getRootElement(), RenderLeave)
	Leave_t.fps = 0
	end
local x,y,z = getElementPosition(localPlayer)
local g= getGroundPosition(x+Leave_t.vel[1],y+Leave_t.vel[2],z)
if isLineOfSightClear ( x,y,z, x+Leave_t.vel[1],y+Leave_t.vel[2],g+1,  true, false, false, true, true, false, false, localPlayer) == true then
setElementPosition(localPlayer,x+Leave_t.vel[1],y+Leave_t.vel[2],g+1 )
end
--dxDrawLine3D (Leave_t.draw[1],Leave_t.draw[2],Leave_t.draw[3],Leave_t.draw[4],Leave_t.draw[5],Leave_t.draw[6] ,tocolor(225,25,25,120),250 )
fxAddGlass (Leave_t.draw[1],Leave_t.draw[2],Leave_t.draw[3],255,25, 25, 20,2, 1 )
end
function onClientColShapeEnter( theElement, matchingDimension )
    if ( theElement == localPlayer ) and source == PolygonA then  
		Leave_t.out = true
	end
end]]
local Leave_t = {keyT=false,keys=false,status=false,out=true,fps = 0,vel={},draw={}}
function onClientColShapeLeave( theElement, matchingDimension )
    if ( theElement == localPlayer ) and source == PolygonA then  
		_core_out_of_range()
		addEventHandler("onClientColShapeHit",getRootElement(),onClientColShapeEnter)
    end
end
addEventHandler("onClientColShapeLeave",getRootElement(),onClientColShapeLeave)

function onClientColShapeEnter( theElement, matchingDimension )
    if ( theElement == localPlayer ) and source == PolygonA then  
		_core_out_of_range_D()
	end
end



function MarkTheRushField(x,y,sX,sY)
	createRadarArea ( x-(sX/2),y-(sY/2), sX,sY )
end
function findRotation(x1,y1,x2,y2)
 
  local t = -math.deg(math.atan2(x2-x1,y2-y1))
  if t < 0 then t = t + 360 end;
  return t;
 
end

local Pdf
function CreateDefRush(x,y)
if getPlayerTeam(localPlayer) == getTeamByType("Defense") then
PolygonA = createColCircle ( x,y, 300 )
Pdf = true

	
	for i=1,180 do
		local x1,y1,z = PobierzPozycjeKamery( x,y,0,i*2 ,300 )	
		 MarkTheRushField(x1,y1,10.5,10.5)
	end
end
end
function DestroyDefRush()
	if Pdf == true then
		destroyElement(PolygonA)
		Pdf = false
			for k,v in pairs(getElementsByType ("radararea" )) do 
				destroyElement(v)
			end
	end
end

function CreateAntiRushZone(table_a,count_a)
local Ploygon_s = {}
local arena = {x={},y={}}
local int = 0
for i=1,count_a do
	for k,v in pairs(table_a[i]) do 
		if k ~= 3 then
		int = int+1
		Ploygon_s[int] = v
		end
	end
end
Ploygon_s[int+1] = Ploygon_s[1]
Ploygon_s[int+2] = Ploygon_s[2]
PolygonA = createColPolygon ( unpack(Ploygon_s)  )

P_t = nil		
P_t = table_a	

	for k,v in pairs(table_a) do 
		table.insert(arena.x,v[1])
		table.insert(arena.y,v[2])
	end

	--[[for j=1, #arena.x-1 do
		local distance = math.round(getDistanceBetweenPoints2D ( arena.x[j],arena.y[j],arena.x[j+1],arena.y[j+1]) ,0)
		local rot = math.round(findRotation(arena.x[j],arena.y[j],arena.x[j+1],arena.y[j+1]),0)
			for i=1,math.round(distance/10,0) do
				local x,y,z = PobierzPozycjeKamery( arena.x[j],arena.y[j],0,rot ,i*10 )	
				MarkTheRushField(x,y,10.5,10.5)
			end
	end
	
		local distance = math.round(getDistanceBetweenPoints2D ( arena.x[#arena.x],arena.y[#arena.x],arena.x[1],arena.y[1]) ,0)
		local rot = math.round(findRotation(arena.x[#arena.x],arena.y[#arena.x],arena.x[1],arena.y[1]),0)
			for i=1,math.round(distance/10,0) do
				local x,y,z = PobierzPozycjeKamery( arena.x[#arena.x],arena.y[#arena.x],0,rot ,i*10 )	
				MarkTheRushField(x,y,10.5,10.5)
			end]]
	for j=1, #arena.x-1 do
		local distance = math.round(getDistanceBetweenPoints2D ( arena.x[j],arena.y[j],arena.x[j+1],arena.y[j+1]) ,0)
		local rot = math.round(findRotation(arena.x[j],arena.y[j],arena.x[j+1],arena.y[j+1]),0)
			for i=1,math.round(distance/5,0) do
				local x,y,z = PobierzPozycjeKamery( arena.x[j],arena.y[j],0,rot ,i*5 )	
				MarkTheRushField(x,y,5.5,5.5)
			end
	end
	
		local distance = math.round(getDistanceBetweenPoints2D ( arena.x[#arena.x],arena.y[#arena.x],arena.x[1],arena.y[1]) ,0)
		local rot = math.round(findRotation(arena.x[#arena.x],arena.y[#arena.x],arena.x[1],arena.y[1]),0)
			for i=1,math.round(distance/5,0) do
				local x,y,z = PobierzPozycjeKamery( arena.x[#arena.x],arena.y[#arena.x],0,rot ,i*5 )	
				MarkTheRushField(x,y,5.5,5.5)
			end
end
minuts = 0
secounds = 0

		function DeleteeAntiRushZone()
			if isElement ( PolygonA ) == true then
				destroyElement(PolygonA)
			end
			for k,v in pairs(getElementsByType ("radararea" )) do 
				destroyElement(v)
			end
		end

FPSLast = 0
local fps_t ={FPSc=0,StartFPSTime= getTickCount() +1000,int=0}
tc_cc = getTickCount()
function onClientPreRender_FPS ( )
	if ( getTickCount() < fps_t.StartFPSTime ) then
		fps_t.FPSc = fps_t.FPSc + 1
	else
		FPSLast = fps_t.FPSc
		fps_t.FPSc = 0
		fps_t.StartFPSTime = getTickCount() + 1000
	end
	fps_t.int = fps_t.int + 1
		if fps_t.int == 350 then
			setElementData ( localPlayer,"FPS",FPSLast)
				if  _game_status == 1 then
					local pl = math.round(k_system.packet[1]/k_system.packet[2],2)
					if type(pl ) == 'number' then
						setElementData ( localPlayer,"P. Loss",pl.."%")
					end	
				else
					setElementData ( localPlayer,"P. Loss"," - ")
				end			
			tc_cc = getTickCount()
		fps_t.int = 0
		end
end	
addEventHandler("onClientPreRender", getRootElement(),onClientPreRender_FPS)




spawn_t = nil
function AddSpawnProtect(id)
 ---// code out
		setTimer(function()
		ehe_p = getElementHealth( localPlayer)
		--setElementData ( localPlayer, "Health",100 )
		addEventHandler("onClientRender", getRootElement(), ehehe)
		end,250,1)
end





	
function Bm_onClientPlayerWasted_Check ( killer, weapon, bodypart )
	if getElementData ( sett,"Round" ) ~= 0 then
		if getElementData(source,"IsSpawned") == 1 then
			if source == localPlayer then
				if getElementData ( sett,"Round" ) == 2 then
					destroyElement(PolygonA)
				else
					DestroyDefRush()
				end
					if killer ~= false and killer ~= localPlayer and getElementData ( killer,"IsSpawned") == 1  then
						got_points(false,"You've been killed by:",getPlayerName(killer))
						--DxDrawTimeText(3500,screenWidth/2.6, screenHeight/1.21,math.round(size1,1),"sans",1, tocolor(0,0,0,255),false,"You've been killed by ",getPlayerName(killer),".",tocolor(200,200,200,255),tocolor(238,180,34,255),tocolor(200,200,200,255))
					end		

				if Selectors[1] == true then
					bm_DestroyWeaponSelector()
				end
			end	
		end
		if getElementData ( source,"IsSpawned") == 1 and killer == localPlayer and source ~= localPlayer then
			local zbyszek = getPlayerName(source)
			got_points(10,'Killing Enemy:',zbyszek)
			local mark = getElementByID ( 'main-marker' )
				if isElementWithinMarker ( source, mark ) then
					setTimer(function() got_points(20,'Killing Enemy In Defense:',tostring(zbyszek)) end,3500,1)
				end
		end	
	end
end
addEventHandler ( "onClientPlayerWasted", getRootElement(), Bm_onClientPlayerWasted_Check )	




function FindOpenSelector()
	if Selectors[1] == true then
		 bm_DestroyWeaponSelector()  
	elseif Selectors[2] == true then
		destroyCarSelect(true)
	elseif Selectors[3] == true then 
		RemoveSpawnProt()	
	end	
	if t_spw_a.a_gui then
		removeEventHandler ( "onClientGUIClick", t_spw_a.a_gui.t1, _core_attack_accept_c )
		removeEventHandler ( "onClientGUIClick", t_spw_a.a_gui.t2, _core_attack_accept_c)
		destroyElement(t_spw_a.a_gui.window)
		t_spw_a = {} t_spw_a_d = {} PlayerInChoosing = false
		showCursor(false)	
		removeEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
	elseif t_spw_a.backg3 then
		w_onMouseClick_Aa(3,true)	
		removeEventHandler("onClientColShapeLeave",getRootElement(),_core_outofrange)
		removeEventHandler ( "onClientDoubleClick", getRootElement(), _core_attack_click2 )
		removeEventHandler ( "onClientClick", getRootElement(), _core_attack_click )
		removeEventHandler ( "onClientGUIClick",getRootElement(),  w_onMouseClick_A)
	end	
			if type(Car_c) == 'table' and isElement(  Car_c[2] ) then
				destroyElement(Car_c[2])
			end
			if type(Car_c) == 'table'  and isElement( Car_c.zone ) then
				destroyElement( Car_c.zone )
				removeEventHandler("onClientColShapeHit",getRootElement(),_core_carzone)
				removeEventHandler("onClientColShapeLeave",getRootElement(),_core_carzone_q)
			end
			if isTimer( v_p_t_sec ) then
				killTimer ( v_p_t_sec )
				removeEventHandler ( "onClientRender", getRootElement(), _on_render_veh_protect )
				local veh_meh = getPedOccupiedVehicle ( localPlayer )
					if veh_meh then
						setElementAlpha( veh_meh, 255 )
					end
			end	
			removeEventHandler("onClientColShapeLeave",getLocalPlayer(),_core_outofrange)
			
	if getElementData ( getLocalPlayer(),"SpectStatus" ) == 1 then
		RemoveSpectateMode(true)
	end	
			
	_game_status = 0		
end

function ReturnPlayerAmmo()
if tostring(getPedSimplestTask ( localPlayer )) == "TASK_SIMPLE_PLAYER_ON_FOOT" and (getTickCount() - exit_tc) > 10000  then
if getElementData ( localPlayer,"IsSpawned" ) == 1 and getPlayerTeam(localPlayer) ~= TableTeams[3] then
removeCommandHandler("rsp", ReturnPlayerAmmo)
setTimer(function() addCommandHandler ( "rsp", ReturnPlayerAmmo ) end,10000,1)
local rX,rY,rZ = getElementVelocity( localPlayer )
local globalslot = getPedWeaponSlot ( localPlayer )
local t_a = {}
local int_c = 1
	for i=2,11 do
	local sts = getPedTotalAmmo ( localPlayer,i )
		if sts ~= false and sts ~= 0 then
		t_a[int_c] = {getPedWeapon (  localPlayer, i ),sts}
		int_c=int_c+1
		end
	end
	 he_use_rsp = true
	callServer("rsp_cmd", localPlayer, globalslot,t_a ) 
	outputChatBox ( "#FF0000** Info:#0AC419 You will be able to use this command after #FF000010 #0AC419sec.", 255, 255, 255, true )
	
	exports.parachute:stopSkyDiving ()
else
	outputChatBox ( "#FF0000** Error:#0AC419 You can use this cmd on round if you aren't dead.", 255, 255, 255, true )
end
else
outputChatBox ( "#FF0000** Error:#0AC419 You can use this cmd if you stand on ground.", 255, 255, 255, true )
end
end
addCommandHandler ( "rsp", ReturnPlayerAmmo )	


local target_bar
function targetingActivated ( target )
	if isElement(target) and getElementType(target) == "vehicle" and target ~= getPedOccupiedVehicle ( LocalPlayer) then
		if target_bar == nil then
		target_bar = target
		addEventHandler("onClientRender", getRootElement(),DrawTargetHealthBar)
		end
	elseif target_bar then
		target_bar = nil
		removeEventHandler("onClientRender", getRootElement(),DrawTargetHealthBar)
	end	
end
addEventHandler ( "onClientPlayerTarget", getRootElement(), targetingActivated )


function DrawTargetHealthBar()
local x,y,z = getElementPosition(LocalPlayer)
	local Vx,Vy,Vz = getElementPosition(target_bar)
		local w,s = getScreenFromWorldPosition (Vx,Vy,Vz)
		if w ~= false then
			local dis3 = getDistanceBetweenPoints3D(x,y,z,Vx,Vy,Vz)
			local Size = math.max(2.25-(dis3/80),1)
			w=w-(25*Size)
			local Hp = math.max(getElementHealth ( target_bar )- 250, 0)
			local col = math.ceil(Hp/100)
			dxDrawRectangle ( w,s, 54*Size, 7*Size,  tocolor ( 0, 0, 0, 125 ))
			dxDrawRectangle ( w+(1*Size),s+(1.75*Size), 52*Size, 3.5*Size, BarColors[1][col])
			dxDrawRectangle ( w+(1*Size),s+(1.75*Size),(5.2*(Hp/75))*Size, 3.5*Size,  BarColors[2][col])	
		end
end
local player_vehicle 
function EnterVehicle ( veh )
			player_vehicle= veh
			addEventHandler("onClientRender", getRootElement(),DrawVehicleHealthBar)
			
end
addEventHandler ( "onClientPlayerVehicleEnter", localPlayer, EnterVehicle )

function VehicleExit ( veh )
	if player_vehicle then
		removeEventHandler("onClientRender", getRootElement(),DrawVehicleHealthBar)
		player_vehicle= nil
	end	
end
addEventHandler ( "onClientPlayerVehicleExit",localPlayer, VehicleExit )
addEventHandler ( "onClientPlayerWasted", localPlayer, VehicleExit )
addEventHandler ( "onClientPlayerSpawn", localPlayer, VehicleExit )


addEventHandler("onClientElementDestroy", getRootElement(), function ()
	if getElementType(source) == "vehicle" and source == player_vehicle  then
		VehicleExit ( source )
	end
end)
function DrawVehicleHealthBar()
local x,y,z = getElementPosition(LocalPlayer)
	local Vx,Vy,Vz = getElementPosition(player_vehicle)
		local w,s = getScreenFromWorldPosition (Vx,Vy,Vz)
		if w ~= false then
			local dis3 = getDistanceBetweenPoints3D(x,y,z,Vx,Vy,Vz)
			local Size = math.max(2.25-(dis3/80),1)
			w=w-(25*Size)
			local Hp = math.max(getElementHealth ( player_vehicle )- 250, 0)
			local col = math.ceil(Hp/100)
			dxDrawRectangle ( w,s, 54*Size, 7*Size,  tocolor ( 0, 0, 0, 125 ))
			dxDrawRectangle ( w+(Size),s+(1.75*Size), 52*Size, 3.5*Size, BarColors[1][col])
			dxDrawRectangle ( w+(Size),s+(1.75*Size),(5.2*(Hp/75))*Size, 3.5*Size,  BarColors[2][col])	
		end
end

--///////////////////////////////////////////////////////////////////


local s 





local dSize = {}



  

local res_gui = {}
local res_dx = {}
function cancelPedDamage ( attacker )
	cancelEvent() -- cancel any damage done to peds
end
addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage )

results_d = {}




function score_render()

	local x,y = guiGetPosition ( results_d.tlo, false	)
	dxDrawImage ( x, y-results_d.low_res[8], results_d.low_res[7], results_d.low_res[8], 'img/scoreboard/background_2.png', 0, 0, 0, results_d.t1color,true )
	dxDrawImage ( x+(results_d.low_res[1]-results_d.low_res[7]), y-results_d.low_res[8], results_d.low_res[7], results_d.low_res[8], 'img/scoreboard/background_2.png', 0, 0, 0, results_d.t2color,true )
	if results_d.b == 1 then
		dxDrawImage (results_d.res_dx.button1[1], results_d.res_dx.button1[2], results_d.low_res[9], results_d.low_res[10], 'img/scoreboard/background_4.png', 0, 0, 0 )
		dxDrawImage (results_d.res_dx.button2[1], results_d.res_dx.button2[2], results_d.low_res[9], results_d.low_res[10], 'img/scoreboard/background_4.png', 0, 0, 0, tocolor(25,25,25,150),false )
	else
		dxDrawImage (results_d.res_dx.button1[1], results_d.res_dx.button1[2], results_d.low_res[9], results_d.low_res[10], 'img/scoreboard/background_4.png', 0, 0, 0, tocolor(25,25,25,150),false )
		dxDrawImage (results_d.res_dx.button2[1], results_d.res_dx.button2[2], results_d.low_res[9], results_d.low_res[10], 'img/scoreboard/background_4.png', 0, 0, 0 )
	end
	dxDrawText('SCORE', results_d.res_dx.button1t[1], results_d.res_dx.button1t[2],screenWidth, screenHeight, results_d.color, results_d.res_dx.size1,  "bankgothic", "left", "top",false, false, true) 
	dxDrawText('ROUNDS', results_d.res_dx.button2t[1], results_d.res_dx.button2t[2],screenWidth, screenHeight, results_d.color2, results_d.res_dx.size1,  "bankgothic", "left", "top",false, false, true) 	

	dxDrawText(results_d.t1name, results_d.res_dx.t1n[1], results_d.res_dx.t1n[2],screenWidth, screenHeight, colors_g.gray , results_d.res_dx.sizet,  "bankgothic", "left", "top",false, false, true) 
	dxDrawText(results_d.t2name, results_d.res_dx.t2n[1], results_d.res_dx.t2n[2],screenWidth, screenHeight, colors_g.gray, results_d.res_dx.sizet,  "bankgothic", "left", "top",false, false, true) 
	dxDrawText(results_d.t1_score, results_d.res_dx.t1s[1], results_d.res_dx.t1s[2],screenWidth, screenHeight, colors_g.gray, results_d.res_dx.size1a/2,  "bankgothic", "left", "top",false, false, true) 
	dxDrawText(results_d.t1_score, results_d.res_dx.t2s[1], results_d.res_dx.t2s[2],screenWidth, screenHeight, colors_g.gray, results_d.res_dx.size1a/2, "bankgothic", "left", "top",false, false, true) 
	dxDrawTextBaQ(results_d.enter, results_d.res_dx.close[1], results_d.res_dx.close[2],screenWidth, screenHeight, colors_g.gray, results_d.res_dx.size1,  "bankgothic", "left", "top",false, false, true) 
	dxDrawTextBaQ(results_d.info, results_d.res_dx.title[1], results_d.res_dx.title[2],screenWidth, screenHeight, colors_g.green, results_d.res_dx.size1,  "bankgothic", "left", "top",false, false, true) 
	dxDrawTextBaQ(results_d.info2, results_d.res_dx.title2[1], results_d.res_dx.title2[2],screenWidth, screenHeight, colors_g.lblue, results_d.res_dx.size1,  "bankgothic", "left", "top",false, false, true) 
	setCameraMatrix(results_d.set_c[1][1],results_d.set_c[1][2],results_d.set_c[1][3],results_d.set_c[2][1],results_d.set_c[2][2],results_d.set_c[2][3])
--	setElementInterior( localPlayer , 34 )
end

	
	

function results_click ( button, state, absoluteX, absoluteY )
	if absoluteX > results_d.res_dx.button1[1] and absoluteX < results_d.res_dx.button1[1] +results_d.low_res[9] and absoluteY > results_d.res_dx.button1[2] and absoluteY < results_d.res_dx.button1[2] +results_d.low_res[10] then
		results_swithc(1)
	elseif absoluteX > results_d.res_dx.button2[1] and absoluteX < results_d.res_dx.button2[1] +results_d.low_res[9] and absoluteY > results_d.res_dx.button2[2] and absoluteY < results_d.res_dx.button2[2] +results_d.low_res[10] then
		results_swithc(2)
	end
end

function results_swithc(int)
	if int == 1 then
		if results_d.tlo ~= results_d.backg then
			guiSetPosition(results_d.backg,(screenWidth-results_d.low_res[1])/2, ( screenHeight-results_d.low_res[2])/2,false)
			guiSetPosition(results_d.backg2,screenWidth, screenHeight,false)
			results_d.tlo = results_d.backg
			results_d.t1_score = "SCORE      K      D      DMG"
			results_d.t2name = getTeamName(TableTeams[2]).." ( "..tostring(getElementData(TableTeams[2],"Score")).." )"
			results_d.res_dx.t2n={getScreenPositionByRelativeViaElement(0.51,-0.07,results_d.backg)}
			results_d.b = 1
			results_d.color = colors_g.black
			results_d.color2 = colors_g.gray
			playSound ( "sounds/blip.wav")
		end	
	else
		if results_d.tlo ~= results_d.backg2 then
			guiSetPosition(results_d.backg,screenWidth, screenHeight,false)
			guiSetPosition(results_d.backg2,(screenWidth-results_d.low_res[1])/2, ( screenHeight-results_d.low_res[2])/2,false)
			results_d.tlo = results_d.backg2
			results_d.t1_score = ""
			results_d.t2name = " ( "..tostring(getElementData(TableTeams[2],"Score")).." ) "..getTeamName(TableTeams[2])
			results_d.res_dx.t2n={getScreenPositionByRelativeViaElement(0.985,-0.07,results_d.backg2)}
			results_d.res_dx.t2n[1]=results_d.res_dx.t2n[1] -dxGetTextWidth ( results_d.t2name, results_d.res_dx.sizet,  "bankgothic" )
			results_d.b = 2
			results_d.color = colors_g.gray
			results_d.color2 = colors_g.black
			playSound ( "sounds/blip.wav")
		end	
	end
end



function CreateResultsTable_(win,round,reason,rounds_,m_win)
	if g_open_s.team == false then
		
		fix_s( )
		results_d = {b=1,cam={10,10,2},res_dx={},res_gui={},color = colors_g.black,color2 = colors_g.gray,match_t={data={}}}
		results_d.set_c = {{PobierzPozycjeKamery( results_d.cam[1],results_d.cam[2],results_d.cam[3]+2,180 ,-5 )},{PobierzPozycjeKamery(results_d.cam[1],results_d.cam[2],results_d.cam[3]+2,180 ,-4 )}	}
	--setCameraMatrix(results_d.set_c[1][1],results_d.set_c[1][2],results_d.set_c[1][3],results_d.set_c[2][1],results_d.set_c[2][2],results_d.set_c[2][3])

		local out_of_blue = {[TableTeams[1]]=1,[TableTeams[2]]=2}
		results_d.ped = createPed (game_settings.skins[1], 7.6, 10.5, 3.1171875,330)
		setElementInterior( results_d.ped , 34 )
		setElementAlpha( results_d.ped ,0 )
		local a = {"time","shift","stretch","strleg"}
		setPedAnimation (results_d.ped ,"PLAYIDLES",a[math.random(1,4)] ,0,true,false)
		results_d.ped2 = createPed ( game_settings.skins[2], 12.5, 10.0, 3.1171875,30)
		setElementInterior( results_d.ped2 , 34 )
		setElementAlpha( results_d.ped2 ,0 )
		a ={{'CRACK','crckdeth1',0.05},
		{'CRACK','crckdeth2',0.05},}
		local b  = math.random(1,2)
		setPedAnimation (results_d.ped2 ,a[b][1],a[b][2] ,0,true,false)

		setTimer(function() CreateResultsTable( win,round,reason,rounds_,m_win) sdasddsadsa(2000) end,1000,1)
			setPedVoice (results_d.ped, "PED_TYPE_PLAYER", "VOICE_PLY_CR" )
	setPedVoice (results_d.ped2, "PED_TYPE_PLAYER", "VOICE_PLY_CR" )
		showPlayerHudComponent ( "radar",false )

					--showChat(false)
	end
end

local end_r_draw = {}
function end_of_the_round(reason)
	fix_s( )
	end_r_draw = {size=math.round(math.min(1.6,math.max(yhy2(900,1.0),0.7)),1),pos={getScreenPositionByRelative(0.2,0.47)},reason=reason}
	end_r_draw.pos[1] = (screenWidth - dxGetTextWidth ( reason, end_r_draw.size,  "bankgothic" ))/2
	--LoadingAnimation(1000,'end_of_the_round_')
	end_of_the_round_()
	
	
	sdasddsadsa(1000)
end

function end_of_the_round_()
	if getElementData ( getLocalPlayer(),"SpectStatus" ) == 1 then
		RemoveSpectateMode(true)
	end
	destroyHudManufacture()
	addEventHandler("onClientRender", getRootElement(), end_of_the_round_Draw)
	--setTimer(function() LoadingAnimation(1000,'end_of_the_round_D') end,2000,1)
	setTimer(function() sdasddsadsa(1000) end_of_the_round_D() end,2000,1)
end

function end_of_the_round_D(reason)
	--[[showPlayerHudComponent ( "radar",false )
	showPlayerHudComponent ( "weapon",false )
	showPlayerHudComponent ( "health",false )
	showPlayerHudComponent ( "ammo",false )
	removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4) 
	removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
	removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_3)
	addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
	addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4) ]]
	removeEventHandler("onClientRender", getRootElement(), end_of_the_round_Draw)
	addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
	callServer("spawn_player_",localPlayer,localPlayer  ) 
	end_r_draw = {}
end
function end_of_the_round_Draw()
	dxDrawRectangle ( 0, 0,screenWidth, screenHeight ,tocolor(0,0,0,127),true)
	dxDrawTextBaQ_c( end_r_draw.reason, end_r_draw.pos[1], end_r_draw.pos[2],screenWidth, screenHeight, colors_g.lblue, end_r_draw.size,  "bankgothic",colors_g.black) 
end

function CreateResultsTable(win,round,reason,rounds_,m_win)
	render_death_cam_rage_delete()

	destroyHudManufacture()
	showPlayerHudComponent ( "radar",false )
	showPlayerHudComponent ( "weapon",false )
	showPlayerHudComponent ( "health",false )
	showPlayerHudComponent ( "ammo",false )
	removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4) 
	removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
	removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_3)
	showChat(false)
	setSkyGradient ( 27, 54, 84 ,110, 137, 166 )
	results_d.set_c = {{PobierzPozycjeKamery( results_d.cam[1],results_d.cam[2],results_d.cam[3]+2,180 ,-5 )},{PobierzPozycjeKamery(results_d.cam[1],results_d.cam[2],results_d.cam[3]+2,180 ,-4 )}	}
	setCameraMatrix(results_d.set_c[1][1],results_d.set_c[1][2],results_d.set_c[1][3],results_d.set_c[2][1],results_d.set_c[2][2],results_d.set_c[2][3])
	setPedVoice (results_d.ped, "PED_TYPE_PLAYER", "VOICE_PLY_CR" )
	setPedVoice (results_d.ped2, "PED_TYPE_PLAYER", "VOICE_PLY_CR" )
	setElementInterior( localPlayer , 34 )
	if round_mode[1] ~= 'normal' then
		local low_res = {2.6,2,1.0,0.2,0.27,0.44,0.27,0.2,0.32,0.44,0.32,0.2,0.6,0.44,0.6,512,256}
			if screenHeight < 768 then
			local mn_ = 1.1
				if screenHeight < 481 then
					mn_ = 1.6
				elseif screenHeight < 601 then
					mn_ = 1.3
				end
				for k,v in ipairs(low_res) do
					if k > 15 then
						low_res[k] = math.round(v/mn_,2)
					end	
				end
			end
		results_d.match_t = {data={},size=math.round(math.min(low_res[1],math.max(yhy2(900,low_res[2]),low_res[3])),1),pos1={getScreenPositionByRelative(low_res[4],low_res[5])},pos2={getScreenPositionByRelative(low_res[6],low_res[7])},pos1I={getScreenPositionByRelative(low_res[8],low_res[9])},pos2I={getScreenPositionByRelative(low_res[10],low_res[11])},posS1={getScreenPositionByRelative(low_res[12],low_res[13])},posS2={getScreenPositionByRelative(low_res[14],low_res[15])},pos4={getScreenPositionByRelative(0.3,0.75)}}
		
		
		results_d.match_t.data.name1 =  getTeamName(TableTeams[1])
		results_d.match_t.data.name2 =  getTeamName(TableTeams[2])
		results_d.match_t.data.score1 = getElementData(TableTeams[1],'Score')
		results_d.match_t.data.score2 =  getElementData(TableTeams[2],'Score')
		results_d.match_t.data.who = ''
			if m_win ~= false then
				results_d.match_t.data.who = getTeamName(m_win)..' Wins The Match!'
			end	
		local r,g,b = getTeamColor(TableTeams[1])
		results_d.t1color = tocolor(r,g,b,235)
		r,g,b = getTeamColor(TableTeams[2])
		results_d.t2color = tocolor(r,g,b,235)
		

		results_d.match_t.images = {low_res[16],low_res[17]}
		results_d.match_t.imag1 = 'img/Flags/NO.png'
		results_d.match_t.imag2 = 'img/Flags/NO.png'
			if fileExists ( 'img/Flags/'..results_d.match_t.data.name1..'.png' ) then
				results_d.match_t.imag1 = 'img/Flags/'..fix_name(results_d.match_t.data.name1)..'.png'
			end	
			if fileExists ( 'img/Flags/'..results_d.match_t.data.name2..'.png' ) then
				results_d.match_t.imag2 = 'img/Flags/'..fix_name(results_d.match_t.data.name2)..'.png'
			end
		
		results_d.match_t.pos1[1] = (results_d.match_t.images[1]/5) +  (( (screenWidth/2) - dxGetTextWidth ( results_d.match_t.data.name1,  results_d.match_t.size ,"bankgothic" ))/2) 
		results_d.match_t.pos2[1] =   ((screenWidth/2) + ( (screenWidth/2) - dxGetTextWidth ( results_d.match_t.data.name2,  results_d.match_t.size ,"bankgothic" ))/2)  -(results_d.match_t.images[1]/5)
		results_d.match_t.pos1I[1] =  (results_d.match_t.images[1]/5) +  ( (screenWidth/2) - results_d.match_t.images[1])/2
		results_d.match_t.pos2I[1] =  ((screenWidth/2) + ( ((screenWidth/2) - results_d.match_t.images[1]))/2) - (results_d.match_t.images[1]/5)
		results_d.match_t.posS1[1] = (results_d.match_t.images[1]/5) +  (( (screenWidth/2) - dxGetTextWidth ( results_d.match_t.data.score1,  results_d.match_t.size*2 ,"bankgothic" ))/2) 
		results_d.match_t.posS2[1] =   ((screenWidth/2) + ( (screenWidth/2) - dxGetTextWidth ( results_d.match_t.data.score2,  results_d.match_t.size*2 ,"bankgothic" ))/2)  -(results_d.match_t.images[1]/5)	
		results_d.match_t.pos4[1] =  (screenWidth - dxGetTextWidth ( results_d.match_t.data.who,  results_d.match_t.size ,"bankgothic" ))/2
	--	setTimer(function() LoadingAnimation(1000,'_CreateResultsTable',win,round,reason,rounds_) end,5000,1)
		setTimer(function() sdasddsadsa(1000) _CreateResultsTable( win,round,reason,rounds_) end,5000,1)
		addEventHandler ( "onClientRender", getRootElement(), match_intro)
	else
		local r,g,b = getTeamColor(TableTeams[1])
		results_d.t1color = tocolor(r,g,b,235)
		r,g,b = getTeamColor(TableTeams[2])
		results_d.t2color = tocolor(r,g,b,235)
		_CreateResultsTable(win,round,reason,rounds_)
	end
end
function match_intro()
		setCameraMatrix(results_d.set_c[1][1],results_d.set_c[1][2],results_d.set_c[1][3],results_d.set_c[2][1],results_d.set_c[2][2],results_d.set_c[2][3])
		dxDrawImage ( results_d.match_t.pos1I[1] , results_d.match_t.pos1I[2] ,results_d.match_t.images[1], results_d.match_t.images[2], results_d.match_t.imag1)
		dxDrawImage ( results_d.match_t.pos2I[1] , results_d.match_t.pos2I[2] ,results_d.match_t.images[1], results_d.match_t.images[2],  results_d.match_t.imag2 )
		dxDrawTextBaQ_c(results_d.match_t.data.name1, results_d.match_t.pos1[1], results_d.match_t.pos1[2],screenWidth, screenHeight, results_d.t1color, results_d.match_t.size,  "bankgothic",colors_g.black) 
		dxDrawTextBaQ_c(results_d.match_t.data.name2, results_d.match_t.pos2[1], results_d.match_t.pos2[2],screenWidth, screenHeight, results_d.t2color, results_d.match_t.size,  "bankgothic",colors_g.black)
 		dxDrawTextBaQ_c(	results_d.match_t.data.score1, results_d.match_t.posS1[1], results_d.match_t.posS1[2],screenWidth, screenHeight, colors_g.gray, results_d.match_t.size*2,  "bankgothic",colors_g.black) 
		dxDrawTextBaQ_c(	results_d.match_t.data.score2, results_d.match_t.posS2[1], results_d.match_t.posS2[2],screenWidth, screenHeight, colors_g.gray, results_d.match_t.size*2,  "bankgothic",colors_g.black) 
		dxDrawTextBaQ_c( results_d.match_t.data.who, results_d.match_t.pos4[1], results_d.match_t.pos4[2],screenWidth, screenHeight, colors_g.gray, results_d.match_t.size,  "bankgothic",colors_g.black) 
end


function _CreateResultsTable(win,round,reason,rounds_)
	removeEventHandler ( "onClientRender", getRootElement(), match_intro)
	setElementAlpha( results_d.ped ,255 )
	setElementAlpha( results_d.ped2 ,255 )
	
	
	
	
	
	results_d.low_res = {840,300,399,418,25,-0.35,418,35,220, 35,140,560,53.5,10,22,40,745,30,190,10,470,18,13,36,20,11,1,0.7}

	if screenHeight < 768 then
	local mn_ = 1.1
		if screenHeight < 481 then
			mn_ = 1.6
		elseif screenHeight < 601 then
			mn_ = 1.3
		end
		for k,v in ipairs(results_d.low_res) do
			results_d.low_res[k] = math.round(v/mn_,0)
		end
	end
	if isElement(fontfonrt) then
		destroyElement(fontfonrt)
	end	
	fontfonrt = guiCreateFont ('others/fonts/TravelingTypewriter.ttf',math.max(7,results_d.low_res[14]) )
	if isElement(fontfonrt2) then
		destroyElement(fontfonrt2)
	end	
	fontfonrt2 = guiCreateFont ('others/fonts/TravelingTypewriter.ttf',results_d.low_res[15] )
	
	
	
	
	results_d.backg = guiCreateStaticImage ( (screenWidth-results_d.low_res[1])/2, ( screenHeight-results_d.low_res[2])/2, results_d.low_res[1], results_d.low_res[3], 'img/scoreboard/background_1.png',false )
	results_d.tlo = results_d.backg
	results_d.info = getTeamName(win).." ("..getElementData(win,"t_type")..") wins the round - "..round
	--results_d.info = "Team#1 ( Deffend ) wins the round - base 45"
	results_d.info2 = reason or " - "
	results_d.t1name = getTeamName(TableTeams[1]).." ( "..tostring(getElementData(TableTeams[1],"Score")).." )"
	results_d.enter = ''
	results_d.t1_t = getElementData(TableTeams[1],"t_type")
	results_d.t2name = getTeamName(TableTeams[2]).." ( "..tostring(getElementData(TableTeams[2],"Score")).." )"
	results_d.t2_t = getElementData(TableTeams[2],"t_type")
	results.list  = {returnTeamListWithKillsDeaths(TableTeams[1]), returnTeamListWithKillsDeaths(TableTeams[2])}
	--results.list  = {{{"Zbyszek","310","2","1","250"},{"Zbyszek","310","2","1","250"},{"Zbyszek","310","2","1","250"},{"Zbyszek","310","2","1","250"}},{ {"Zbyszek","310","2","1","250"},{"Zbyszek","310","2","1","250"},{"Zbyszek","310","2","1","250"},{"Zbyszek","310","2","1","250"}}}

	results_d.t1_score = "SCORE      K      D      DMG"
	results_d.t2_score = "SCORE      K      D      DMG"
	
	results_d.res_dx = {title={getScreenPositionByRelativeViaElement(0.0,-0.35,results_d.backg)},title2={getScreenPositionByRelativeViaElement(0.0,1.1,results_d.backg)},sizet=math.max(yhy2(900,0.8),0.6),size1=math.max(yhy2(900,1),0.7),size1a=yhy2(900,results_d.low_res[27]),size2=math.max(yhy2(900,0.6),0.45),close={getScreenPositionByRelativeViaElement(0.25,1.27,results_d.backg)},t1n={getScreenPositionByRelativeViaElement(0.01,-0.07,results_d.backg)},t2n={getScreenPositionByRelativeViaElement(0.51,-0.07,results_d.backg)},t1s={getScreenPositionByRelativeViaElement(0.22,-0.055,results_d.backg)},t2s={getScreenPositionByRelativeViaElement(0.72,-0.055,results_d.backg)},button1={getScreenPositionByRelativeViaElement(0.0,-0.23,results_d.backg)},button2={getScreenPositionByRelativeViaElement(0.275,-0.23,results_d.backg)},button1t={getScreenPositionByRelativeViaElement(0.055,-0.225,results_d.backg)},button2t={getScreenPositionByRelativeViaElement(0.325,-0.225,results_d.backg)}}
	
	results_d.res_dx.title[1] = (screenWidth - dxGetTextWidth ( results_d.info, results_d.res_dx.size1,  "bankgothic" ))/2
	results_d.res_dx.title2[1] = (screenWidth - dxGetTextWidth ( reason or " - ", results_d.res_dx.size1,  "bankgothic" ))/2
		for k,v in pairs(results_d.res_gui) do
			if getElementType(v) == "gui-label" then
					guiLabelSetColor(v,235,235,235)
			end
		end	

	local b_x,b_y = getRelativeByScreenPositionViaElement(results_d.low_res[4],results_d.low_res[5],results_d.backg)
	local summary = {{0,0,0,0,0},{0,0,0,0,0}}
	for j=1,2 do
	local l_pos = {{{0.0,0.23,0.32,0.405},{0.504,0.72,0.81,0.895}},0.0}
		local count = 0
		
		for k,v in pairs(results.list[j]) do
		
		local text_ = v[1]..string.rep(" ",results_d.low_res[24]-string.len(v[1]) )..v[2]..string.rep(" ",results_d.low_res[25]-string.len(v[2]) )..v[3]..string.rep(" ",results_d.low_res[26]-string.len(v[3]) )..v[4]..string.rep(" ",results_d.low_res[23]-string.len(v[4]) )..v[5]
		local asda = guiCreateStaticImage ( l_pos[1][j][1],l_pos[2], b_x,b_y, 'img/scoreboard/background_3.png',true,results_d.backg )
		guiSetAlpha(asda,0.25)
		results_d.res_gui["t1_"..tostring(k)] = guiCreateLabel(l_pos[1][j][1] +0.025,l_pos[2]+0.007,0.5,0.5,text_ ,true,results_d.backg)
		
		guiSetFont(results_d.res_gui["t1_"..tostring(k)] ,fontfonrt)
			for i =2,5 do
				if type ( tonumber( v[i] ) ) == 'number' then
					summary[j][i] = summary[j][i] +  tonumber(v[i])
				end
			end	

	count = count+1
		l_pos[2]=l_pos[2]+b_y

		end
	end
		l_pos = {{{0.0,0.23,0.32,0.405},{0.505,0.72,0.81,0.895}},0.94}
		for j=1,2 do
				local text_ = "Total:"..string.rep(" ",results_d.low_res[10]-string.len("Total:") )..summary[j][2]..string.rep(" ",results_d.low_res[22]-string.len(summary[j][2]) )..summary[j][3]..string.rep(" ",results_d.low_res[23]-string.len(summary[j][3]) )..summary[j][4]..string.rep(" ",results_d.low_res[23]-string.len(summary[j][4]) )..summary[j][5]
		results_d.res_gui["t_s"..tostring(j).."-"] = guiCreateLabel(l_pos[1][j][1] +0.04,l_pos[2]+0.007,0.5,0.1,text_ ,true,results_d.backg)
		local x,y = guiGetPosition ( results_d.res_gui["t_s"..tostring(j).."-"], false )
		local sx,sy = guiGetSize  ( results_d.res_gui["t_s"..tostring(j).."-"], false  )
		results_d.res_gui["t_s"..tostring(j)] = guiCreateLabel(x-1,y-1,sx,sy,text_ ,false,results_d.backg)
		
		
		guiSetFont(results_d.res_gui["t_s"..tostring(j)] ,fontfonrt)
		guiSetFont(results_d.res_gui["t_s"..tostring(j).."-"] ,fontfonrt)
		guiLabelSetColor(results_d.res_gui["t_s"..tostring(j).."-"],0,0,0)
		end
		results_d.backg2 = guiCreateStaticImage ( screenWidth, screenHeight, results_d.low_res[1], results_d.low_res[3], 'img/scoreboard/background_1.png',false )
		local o = 0
	--	local rounds_ = {{'Base: 45',TableTeams[2],'Attack','Defense','Outdoors','1','80'},{'Base: 15',TableTeams[2],'Attack','Defense','Balaba','5','380'},{'Base: 3',TableTeams[1],'Defense','Attack','Campa','3','130'},{'Base: 14',TableTeams[1],'Attack','Defense','Outdoors','1','80'},{'Base: 55',TableTeams[2],'Attack','Defense','Outdoors','1','80'},{'Base: 75',TableTeams[1],'Defense','Attack','Outdoors','1','80'},{'Arena: 2',TableTeams[2],'Attack','Defense',' - ','0','0'}}
		local summary_r = {[TableTeams[1]]={0,0},[TableTeams[2]]={0,0}}
			for k,v in ipairs(rounds_) do
				if v[2] == TableTeams[1] then
					summary_r[TableTeams[1]][1] = summary_r[TableTeams[1]][1]+1
					summary_r[TableTeams[2]][2] = summary_r[TableTeams[2]][2]+1
					results_d.left = guiCreateStaticImage ( 0,o, results_d.low_res[11], results_d.low_res[13], 'img/scoreboard/background_5.png',false,results_d.backg2 )
					results_d.right = guiCreateStaticImage ( results_d.low_res[12]+results_d.low_res[11],o, results_d.low_res[11], results_d.low_res[13], 'img/scoreboard/background_6.png',false,results_d.backg2 )
					local t_ = guiCreateLabel(results_d.low_res[16],o,100,50,'WIN' ,false,results_d.backg2)
					guiSetFont(t_ ,fontfonrt2)	
					t_ = guiCreateLabel(735,o,100,50,'LOSS' ,false,results_d.backg2)
					guiSetFont(t_ ,fontfonrt2)	
					local d_ = {'Attack','Defend'}
					if v[3] == v[2] then
						 d_ = {'Attack','Defend'}
					else
						 d_ = {'Defend','Attack'}
					end
					t_ = guiCreateLabel(results_d.low_res[16],o+results_d.low_res[18],100,50,'( '..d_[1]..' )' ,false,results_d.backg2)
					guiSetFont(t_ ,fontfonrt)
					t_ = guiCreateLabel(results_d.low_res[17],o+results_d.low_res[18],100,50,'( '..d_[2]..' )' ,false,results_d.backg2)
					guiSetFont(t_ ,fontfonrt)
				else
					summary_r[TableTeams[1]][2] = summary_r[TableTeams[1]][2]+1
					summary_r[TableTeams[2]][1] = summary_r[TableTeams[2]][1]+1
					results_d.left = guiCreateStaticImage ( 0,o, results_d.low_res[11], results_d.low_res[13], 'img/scoreboard/background_6.png',false,results_d.backg2 )
					results_d.right = guiCreateStaticImage ( results_d.low_res[12]+results_d.low_res[11],o, results_d.low_res[11], results_d.low_res[13], 'img/scoreboard/background_5.png',false,results_d.backg2 )
					local t_ = guiCreateLabel(results_d.low_res[18],o,100,50,'LOSS' ,false,results_d.backg2)
					guiSetFont(t_ ,fontfonrt2)	
					t_ = guiCreateLabel(results_d.low_res[17],o,100,50,'WIN' ,false,results_d.backg2)
					guiSetFont(t_ ,fontfonrt2)
					local d_ = {'Attack','Defend'}
					if v[3] == v[2] then
						  d_ = {'Defend','Attack'}
					else
						  d_ = {'Attack','Defend'}
					end
					t_ = guiCreateLabel(results_d.low_res[17],o+results_d.low_res[18],100,50,'( '..d_[1]..' )' ,false,results_d.backg2)
					guiSetFont(t_ ,fontfonrt)
					t_ = guiCreateLabel(results_d.low_res[16],o+results_d.low_res[18],100,50,'( '..d_[2]..' )' ,false,results_d.backg2)
					guiSetFont(t_ ,fontfonrt)
				end				
				results_d.center = guiCreateStaticImage ( results_d.low_res[11],o, results_d.low_res[12], results_d.low_res[13], 'img/scoreboard/background_7.png',false,results_d.backg2 )
			--[[	guiSetAlpha(results_d.left,0.75)
				guiSetAlpha(results_d.center,0.5)
				guiSetAlpha(results_d.right,0.75)]]
				
				local t_ = guiCreateLabel(results_d.low_res[19],o+results_d.low_res[20],200,50,v[1] ,false,results_d.backg2)
				guiSetFont(t_ ,fontfonrt2)	
				guiLabelSetColor ( t_,55,55,55 )
				t_ = guiCreateLabel(results_d.low_res[21],o+results_d.low_res[20],150,50,'Type: '..tostring(v[4]) ,false,results_d.backg2)
				guiSetFont(t_ ,fontfonrt)
				guiLabelSetColor ( t_,55,55,55 )	
				t_ = guiCreateLabel(results_d.low_res[21],o+results_d.low_res[18],200,50,tostring(v[5])..' player(s) left with '..tostring(v[6])..' hp' ,false,results_d.backg2)
				guiSetFont(t_ ,fontfonrt)
				guiLabelSetColor ( t_,55,55,55 )


		
		o=o+53.4
		end
				for i=1,2 do
						t_ = guiCreateLabel(0.1,0.95,0.4,0.1,summary_r[TableTeams[1]][1].." rounds wins, "..summary_r[TableTeams[1]][2].." rounds loss" ,true,results_d.backg2)
				guiSetFont(t_ ,fontfonrt)
					local _x,_y = getRelativeByScreenPosition(guiLabelGetTextExtent ( t_ ),guiLabelGetFontHeight ( t_ ),results_d.backg2)
					guiSetPosition(t_,(0.49-_x)/2,0.9+(0.1-_y)/2,true)
				if i ==1 then
					guiLabelSetColor ( t_,0,0,0 )
					local x,y = guiGetPosition(t_,false)
					guiSetPosition(t_,x+1,y+1,false)


				end
				
				
						t_ = guiCreateLabel(0.6,0.95,0.4,0.1,summary_r[TableTeams[2]][1].." rounds wins, "..summary_r[TableTeams[2]][2].." rounds loss" ,true,results_d.backg2)
				guiSetFont(t_ ,fontfonrt)
					
						local _x,_y = getRelativeByScreenPosition(guiLabelGetTextExtent ( t_ ),guiLabelGetFontHeight ( t_ ))
						guiSetPosition(t_,0.505+(0.49-_x)/2,0.9+(0.1-_y)/2,true)
					if i ==1 then
						guiLabelSetColor ( t_,0,0,0 )
					
						local x,y = guiGetPosition(t_,false)
						guiSetPosition(t_,x+1,y+1,false)

					end
				end
	
showCursor(true)
addEventHandler ( "onClientClick", getRootElement(), results_click)
	addEventHandler("onClientRender", getRootElement(), score_render)
	setTimer(function()
	results_d.enter = 'Press Enter To Hide'
	results_d.res_dx.close[1] = (screenWidth - dxGetTextWidth ( results_d.enter, results_d.res_dx.size1,  "bankgothic" ))/2
	bindKey ( "enter", "up", HideResultsT )
	end,4000,1)
end


--setTimer(function() CreateResultsTable_() end,3000,1)

function HideResultsT()
	unbindKey ( "enter", "up", HideResultsT )
		HideResultsT_()
	--	LoadingAnimation(1000,'HideResultsT_')
		sdasddsadsa(1000)
		

	_client_panel_save()
	
end 
function HideResultsT_(m)
assist_t = {}	
showCursor(false)
removeEventHandler ( "onClientClick", getRootElement(), results_click)
	removeEventHandler("onClientRender", getRootElement(), score_render)

		resetSkyGradient()
		
		destroyElement(results_d.ped)
		destroyElement(results_d.ped2)

showPlayerHudComponent ( "radar",true )
showPlayerHudComponent ( "radar",true )
showPlayerHudComponent ( "weapon",true )
showPlayerHudComponent ( "health",true )
showPlayerHudComponent ( "ammo",true )
					

				--	addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_3)



	
for k,v in pairs(results_d.res_gui) do
	if isElement(v) then
		destroyElement(v)
	end
end
for k1,v1 in pairs(results_d) do
	if isElement(v1) then
		destroyElement(v1)
	end
end
results_d = {}
					if m ~= true then
						syncInterior( localPlayer, 0 )
						addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
						addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4) 
						callServer("spawn_player_",localPlayer,localPlayer  ) 
					end
					showChat(true)
					collectgarbage ("collect")
end 

local _core_out = {}
function _core_out_of_range()
	playSound ( 'sounds/no.ogg' )
	addEventHandler("onClientHUDRender", getRootElement(), _core_out_of_range_Draw)
	_core_out = {size=math.round(math.min(1.6,math.max(yhy2(900,1.0),0.7)),1),pos={getScreenPositionByRelative(0.2,0.35)},count=5}
	_core_out.pos[1] = (screenWidth - dxGetTextWidth ( "Or you will be annihilated in 5 seconds.", _core_out.size,  "bankgothic" ))/2
	_core_out.timers = {setTimer(function() _core_out.count = _core_out.count-1 for i=1, 5 do playSoundFrontEnd ( 101 ) end  end,1000,4), setTimer(function() _core_out_of_range_D() callServer("killPed", localPlayer,localPlayer,11,4)  end,5100,1)}
end

function _core_out_of_range_D()
	removeEventHandler("onClientHUDRender", getRootElement(), _core_out_of_range_Draw)
	removeEventHandler("onClientColShapeHit",getRootElement(),onClientColShapeEnter)
		for k,v in pairs(_core_out.timers) do
			if isTimer( v ) then
				killTimer ( v )
			end	
		end
	_core_out = {}
end
function _core_out_of_range_Draw()
	dxDrawRectangle ( 0, 0,screenWidth, screenHeight ,tocolor(0,0,0,100),true)
	dxDrawTextBaQ_c( "\
	                    Turn back!\n\
	Or you will be annihilated in ".. _core_out.count .." seconds.", _core_out.pos[1], _core_out.pos[2],screenWidth, screenHeight, colors_g.lblue, _core_out.size,  "bankgothic",colors_g.black) 
end


--//////////////////////////////////////////////////////////////

local Drop_weapons = {}

local dx_drop_weapons_t = {
[22]={"glock.png","Pistol"},
[23]={"slient.png","Silenced Pistol"},
[24]={"deagle.png","Desert Eagle"},
[25]={"shotgun.png","Shotgun"},
[29]={"mp5.png","MP5"},
[30]={"ak47.png","AK-47"},
[31]={"m4.png","M4"},
[33]={"rifle.png","Rifle"},
[34]={"sniper.png","Sniper Rifle"},

}
local dx_drop_global_t = 
{txt1={getScreenPositionByRelative(0.375,0.7)},
img1={getScreenPositionByRelative(0.41,0.725)},
img1_s={getScreenPositionByRelative(0.146,0.065)},
}
local dx_drop_local_t = {cTimer=false,lastCol=false,weapon=24}
local SlotsToChange = {
[0] = {0},
[1] = {2},
[2] = {3,4,5,6},
}
function GetDropSlot(id)
	for i=0,2 do
		for k,v in ipairs(SlotsToChange[i]) do
			if v == id then
			return i
			end
		end
	end	
	return 0
end

function synchronize_drop(c,id,type,o)
	if o ~= nil then
	 setElementCollisionsEnabled ( o, false )
	end
	if type == "new" then
 table.insert(Drop_weapons,{c,id})
 
	elseif type == "del" then
	local k = FindColinTable(c)
	Drop_weapons[k] = {}
		if dx_drop_local_t.lastCol ~= false then
		removeEventHandler("onClientRender", getRootElement(),dxDraw_drow)
		removeEventHandler("onClientColShapeLeave",getRootElement(),onClientColShapeLeave22)
		if dx_drop_local_t.cTimer ~= false then
			killTimer(dx_drop_local_t.cTimer)
		end	
		end
	else

	local k = FindColinTable(c)

	Drop_weapons[k] = {}
	Drop_weapons[k] = {c,id}
	dx_drop_local_t.weapon = Drop_weapons[k][2]
	end
end
function FindColinTable(id)
	for k,v in pairs(Drop_weapons) do
		if v[1] == id then
		return k
		end
	end
	return false
end

function dxDraw_drow()
dxDrawColorText(dx_drop_global_t.txt1[1],dx_drop_global_t.txt1[2],size1,"default-bold",0, colors_g.black,false,"Press ","F"," to change on "..dx_drop_weapons_t[dx_drop_local_t.weapon][2]..".",colors_g.gray,colors_g.gold,colors_g.gray)
dxDrawImage ( dx_drop_global_t.img1[1],dx_drop_global_t.img1[2],dx_drop_global_t.img1_s[1],dx_drop_global_t.img1_s[2], "img/mini/"..dx_drop_weapons_t[dx_drop_local_t.weapon][1] )
end

function DropWeapon(cmd,id,clip,ammo)
local x,y,z = getElementPosition(localPlayer)
x,y,z = PobierzPozycjeKamery( x,y,z,getPedRotation(localPlayer) ,0.5 )	
local g = getGroundPosition( x,y,z)
callServer("CreateDropWeaponPoint",x,y,g,tonumber(id),tonumber(clip),tonumber(ammo))

end

function onClientColShapeHit22( theElement, matchingDimension )
    if ( theElement == localPlayer ) then  -- Checks whether the entering element is the local player
		if getElementID(source) == "w_col" then
		if getElementHealth ( localPlayer  ) ~= 0 then
		local k = FindColinTable(source)
		dx_drop_local_t.lastCol = source
		dx_drop_local_t.weapon = Drop_weapons[k][2]
		addEventHandler("onClientRender", getRootElement(),dxDraw_drow)
		addEventHandler("onClientColShapeLeave",getRootElement(),onClientColShapeLeave22)
		dx_drop_local_t.cTimer = setTimer(CheckThisOutBithc,5000,1)
		end
		end
    end
end
addEventHandler("onClientColShapeHit",getRootElement(),onClientColShapeHit22)

function onClientColShapeLeave22( theElement, matchingDimension )
    if source == dx_drop_local_t.lastCol then  -- Checks whether the leaving element is the local player
		dx_drop_local_t.lastCol = false
		removeEventHandler("onClientRender", getRootElement(),dxDraw_drow)
		removeEventHandler("onClientColShapeLeave",getRootElement(),onClientColShapeLeave22)
		if dx_drop_local_t.cTimer ~= false then
			killTimer(dx_drop_local_t.cTimer)
		end	
    end
end

function CheckThisOutBithc()
	if dx_drop_local_t.lastCol ~= false then
		dx_drop_local_t.lastCol = false
		dx_drop_local_t.cTimer = false
		removeEventHandler("onClientRender", getRootElement(),dxDraw_drow)
		removeEventHandler("onClientColShapeLeave",getRootElement(),onClientColShapeLeave22)
	end
end

function getDropWeap(s)
	for k,v in pairs(SlotsToChange[s]) do
		local lw = getPedWeapon ( localPlayer,v  )
			if lw ~= 0 then
				return v
			end
	end
end

function change_drop()
if getElementHealth ( localPlayer  ) ~= 0 then
local lp = localPlayer
	for k,v in pairs(Drop_weapons) do
		if isElementWithinColShape ( lp, v[1] ) == true then
			local slot_f = GetDropSlot(getSlotFromWeapon ( v[2] ))

			local slot = getDropWeap(slot_f)
		
			local weapon = getPedWeapon ( lp,slot  )
			local clip = getPedAmmoInClip ( lp,slot  )
			local ammo = getPedTotalAmmo ( lp,slot  ) 
		
			 callServer("ShitchDropWeaponPoint",v[1],weapon,clip, ammo,lp)
			return
		end
	end
end
end
bindKey ( "f", "up",change_drop )
function addfornewthink(slot)

	if slot == 0 or slot == 8 then
	return getPedWeapon ( localPlayer, 2 ),2
	elseif slot == 2 then
		for i=4,6 do 
		local n = getPedWeapon ( localPlayer, i )
			if n ~= 0 then
			return n,i
			end
		end
	end	
	return getPedWeapon ( localPlayer  )
end

function bmc_onClientPlayerWasted ( killer, weapon, bodypart )
local lp = localPlayer
	if getElementData ( lp,"IsSpawned") == 1 then
	local slot = getPedWeaponSlot ( lp )
	--if slot == 2 or slot == 3 or slot == 4  or slot == 5  or slot == 6 then 
		local weapon,nslot =  addfornewthink(slot)
		if weapon ~= 0 then
			local clip = getPedAmmoInClip ( lp,nslot   )
			local ammo = getPedTotalAmmo ( lp,nslot   ) 
			local x,y,z = getElementPosition(lp)
			x,y,z = PobierzPozycjeKamery( x,y,z,getPedRotation(lp) ,0.5 )	
			local g = getGroundPosition( x,y,z)
			callServer("CreateDropWeaponPoint",x,y,g,weapon,clip,ammo)
			--end
			_client_panel_save()
		end
	end
	--exports.parachute:removeParachute ( localPlayer,"land")
	exports.parachute:stopSkyDiving ()
end
addEventHandler ( "onClientPlayerWasted", localPlayer, bmc_onClientPlayerWasted ) 

function updatelogget_out(sts)
logget_out = sts
end
local  _panel = {}
	function movePanel()
		guiSetPosition (_panel.window, (screenWidth-550)/2, (screenHeight-350)/2,false )
	end

	function _panel_window(data,history_data)
		function accept() 
			if source == _panel.close then
				showCursor(false)
				removeEventHandler ( "onClientGUIClick",_panel.close, accept )	
				removeEventHandler ( "onClientClick",getRootElement() , bring )	
				destroyElement(_panel.window )
				_panel = {}
			end
		end
		function bring() 
			guiMoveToBack( _panel.tab )
		end
		addEventHandler ( "onClientGUIClick",_panel.close, accept, true )	
		addEventHandler ( "onClientClick",getRootElement() , bring, true )	
		showCursor(true)
	end
	
local c_panel_read_only_c = getTickCount()	- 9999
	
	function createConfiguartionPanel()
	local read_only = false
	local read_only_t = ""
		if _panel.window  then
			showCursor(false)
			removeEventHandler ( "onClientGUIClick",_panel.close, accept )	
			removeEventHandler ( "onClientClick",getRootElement() , bring )	
			destroyElement(_panel.window )
			_panel = {}
			return false
		end
		if help.window  then
			return false
		end
		if logget_out == nil then
			if getTickCount() - c_panel_read_only_c < 9999 then
				outputChatBox ( "#FF0000** Error:#0AC419 In mode 'read only' you can open configuration panel #ffae00only once every ten seconds.",255, 255, 255, true )
				return false
			end
			c_panel_read_only_c = getTickCount()	
			read_only = true
			read_only_t = " (READ ONLY MODE)"
			outputChatBox ( "#FF0000** Error:#0AC419 you are not admin... #ffae00Configuration panel will work in 'read only' mode.",255, 255, 255, true )
			
		end
		 _panel = {read_only=read_only,save = {},weapons_l = {},edit={},edit_={},teams_l ={{Name='123123',Skin='57',Score='0',Color='125,23,125'},{Name='1sadsa',Skin='157',Score='0',Color='225,23,25'}}}
		local settings_l ={22,23,24,25,26,27,28,29,32,30,31,33,34,37,38,16,17,18,39}			
			for k,i in ipairs(settings_l) do
				_panel.weapons_l[i] = {['Ammo']=tostring(math.random(0,100)),['Skills']=tostring(math.random(0,100)),['Primary weapon']='true',['Secondary weapon']='false',['Special weapon']='false'}
			end
						
		
		_panel.window = guiCreateWindow ((screenWidth-550)/2, (screenHeight-350)/2, 550, 350, "A/D Aspect 1.0: Configuration panel."..read_only_t,false )
		guiSetAlpha ( _panel.window, 0 )
		_panel.info = guiCreateLabel ( 0.46, 0.49, 0.2, 0.1, 'Loading...',true )
		guiSetFont ( _panel.info,myFont )
		_panel.tab = guiCreateTabPanel (0.01, 0.14, 0.98, 0.93, true, _panel.window )
		guiSetFont ( 	_panel.tab,myFont )
		_panel.b_save = guiCreateButton ( 0.29, 0.063, 0.2, 0.064, 'Save',  true, _panel.window  )
		_panel.b_save_as = guiCreateButton ( 0.51, 0.063, 0.2, 0.064, 'Save as',  true, _panel.window  )
		_panel.b_delete = guiCreateButton ( 0.73, 0.063, 0.2, 0.064, 'Delete',  true, _panel.window  )
		_panel.c_confings = guiCreateComboBox ( 0.01, 0.06, 0.25, 0.5, 'Confings' ,true, _panel.window )
		_panel.settings = guiCreateTab ( "Settings", _panel.tab )
		_panel.grid_settings = guiCreateGridList (  0.015, 0.025, 0.97, 0.95 ,true, _panel.settings )
		guiGridListSetSelectionMode (_panel.grid_settings, 0 )
        guiGridListAddColumn ( _panel.grid_settings , 'Settings', 0.5 )
			  guiGridListAddColumn ( _panel.grid_settings , 'Value', 0.4 )
		local settings_l ={{'Base Time','08:20'},{'Arena Time','05:20'},{'Crouch Bug','alternative'},{'Anti Cheat','simple'},{'FPS Limit','25'},{'Minimal fps','25'},{'Maximal ping','350'},{'Maximal packet loss','0.1%'},{'Anti Car Kill','true'},{'Anti Helli Kill','true'},{'Enable Knife','true'},{'Hide Health','false'},{'Auto Puase','true'}}
			for k,v in ipairs(settings_l) do
				local row = guiGridListAddRow (_panel.grid_settings )
				guiGridListSetItemText ( _panel.grid_settings, row, 1, v[1], false, false )

				guiGridListSetItemText ( _panel.grid_settings, row, 2, v[2], false, false )
			end
		--// Players
		
		_panel.players = guiCreateTab ( "Players", _panel.tab )
		_panel.grid_players = guiCreateGridList (  0.015, 0.025, 0.3, 0.95 ,true, _panel.players  )
		guiGridListSetSelectionMode (_panel.grid_players , 0 )
        guiGridListAddColumn ( _panel.grid_players  , 'Players:', 0.8 )
		local ppl = getElementsByType("player")
			for k,v in ipairs(ppl) do
				local row = guiGridListAddRow (_panel.grid_players  )
				local a = guiGridListSetItemText ( _panel.grid_players , row, 1, getPlayerName(v), false, false )
			end
		_panel.memo_players = guiCreateMemo ( 0.35, 0.065, (0.77-0.35)+0.175, 0.350-0.06, 'Select player from list on the right side..', true, _panel.players )
		guiMemoSetReadOnly ( _panel.memo_players,true )
		_panel.b_kick = guiCreateButton ( 0.35, 0.065+0.35, 0.175, 0.08, 'Kick',  true, _panel.players  )	
		_panel.b_ban = guiCreateButton ( 0.56, 0.065+0.35, 0.175, 0.08, 'Ban',  true, _panel.players  )	
		_panel.b_name = guiCreateButton ( 0.77, 0.065+0.35, 0.175, 0.08, 'Change Name',  true, _panel.players  )
		_panel.b_add_ = guiCreateButton ( 0.35, 0.21+0.35, 0.175, 0.08, 'Add',  true, _panel.players  )	
		_panel.b_restore = guiCreateButton ( 0.56, 0.21+0.35, 0.175, 0.08, 'Restore',  true, _panel.players  )	
		_panel.b_remove_ = guiCreateButton ( 0.77, 0.21+0.35, 0.175, 0.08, 'Remove',  true, _panel.players  )
		_panel.b_team = guiCreateButton ( 0.35, 0.355+0.35, 0.175, 0.08, 'Set Team',  true, _panel.players  )	
		_panel.b_heal = guiCreateButton ( 0.56, 0.355+0.35, 0.175, 0.08, 'Heal',  true, _panel.players  )	
		_panel.b_gun = guiCreateButton ( 0.77, 0.355+0.35, 0.175, 0.08, 'Gun menu',  true, _panel.players  )
		_panel.b_healall = guiCreateButton ( 0.35, 0.5+0.35, (0.77-0.35)+0.175, 0.08, 'Heal all players',  true, _panel.players  )
			
		  --// Druzyny
		  
		  _panel.teams = guiCreateTab ( "Teams", _panel.tab )
		  _panel.grid_teams = guiCreateGridList (  0.015, 0.025, 0.3, 0.84 ,true,  _panel.teams )
			guiGridListSetSelectionMode (_panel.grid_teams, 0 )
			guiGridListAddColumn ( _panel.grid_teams , 'Teams', 0.8 )
			local settings_l ={getTeamName(TableTeams[1]),getTeamName(TableTeams[2])}
				for k,v in ipairs(settings_l) do
					local row = guiGridListAddRow (_panel.grid_teams )
					guiGridListSetItemText ( _panel.grid_teams, row, 1, v, false, false )
				end
				local settings_l ={{'Name','xsadadsaads'},{'Skin','123'},{'Score','0'},{'Color','255,123,145'}}	
		  _panel.grid_teams2 = guiCreateGridList (  0.315, 0.025, 0.67, 0.84 ,true, _panel.teams )
		  guiGridListAddColumn ( _panel.grid_teams2 , 'Setting name', 0.5 )
		  guiGridListAddColumn ( _panel.grid_teams2 , 'Value', 0.3 )
				for k,v in ipairs(settings_l) do
					local row = guiGridListAddRow ( _panel.grid_teams2 )
				guiGridListSetItemText ( _panel.grid_teams2, row, 1, v[1], false, false )
				guiGridListSetItemText ( _panel.grid_teams2, row, 2, v[2], false, false )
					if v[1] == 'Color' then
						guiGridListSetItemColor (  _panel.grid_teams2, row, 2, gettok (v[2], 1, string.byte(',')),gettok (v[2], 2, string.byte(',')),gettok (v[2], 3, string.byte(',')))

					end
				end
		_panel.b_balance = guiCreateButton ( 0.04, 0.89, 0.28, 0.07, 'Auto Balance',  true,  _panel.teams  )
		_panel.b_switch = guiCreateButton ( 0.36, 0.89, 0.28, 0.07, 'Switch Sides',  true,  _panel.teams )
		_panel.b_reset = guiCreateButton ( 0.68, 0.89, 0.28, 0.07, 'Reset score and stats',  true,  _panel.teams  )
		_panel.weapon = guiCreateTab ( "Weapons", _panel.tab )

		_panel.grid_weapons_1 = guiCreateGridList (  0.015, 0.025, 0.3, 0.95 ,true,  _panel.weapon )
		guiGridListSetSelectionMode (_panel.grid_weapons_1, 0 )
		guiGridListAddColumn ( _panel.grid_weapons_1 , 'Weapons', 0.8 )
			local settings_l ={22,23,24,25,26,27,28,29,32,30,31,33,34,37,38,16,17,18,39}
				for k,i in ipairs(settings_l) do
					local v = getWeaponNameFromID ( i )
					if v then
						local row = guiGridListAddRow (_panel.grid_weapons_1 )
						guiGridListSetItemText ( _panel.grid_weapons_1, row, 1,v, false, false )
					end	
				end
		_panel.grid_weapons_2 = guiCreateGridList (  0.315, 0.025, 0.67, 0.95 ,true, _panel.weapon)
		guiGridListAddColumn ( _panel.grid_weapons_2 , 'Setting name', 0.5 )
		guiGridListAddColumn ( _panel.grid_weapons_2 , 'Value', 0.3 )
		local settings_l ={{'Ammo','120'},{'Skills','9999'},{'Primary weapon','true'},{'Secondary weapon','false'},{'Special weapon','false'},{'Weapon limit per team','0'}}	
					for k,v in pairs(settings_l) do
					local row = guiGridListAddRow ( _panel.grid_weapons_2  )
				guiGridListSetItemText ( _panel.grid_weapons_2 , row, 1, v[1], false, false )
				guiGridListSetItemText ( _panel.grid_weapons_2 , row, 2, v[2], false, false )
				end
		_panel.vehicles = guiCreateTab ( "Vehicles", _panel.tab )
		_panel.grid_vehicles_1 = guiCreateGridList (  0.015, 0.025, 0.428, 0.95 ,true,  _panel.vehicles )
		guiGridListSetSelectionMode (_panel.grid_vehicles_1, 0 )
		guiGridListAddColumn ( _panel.grid_vehicles_1 , 'Enabled Vehicles', 0.8 )
	
		_panel.grid_vehicles_2 = guiCreateGridList (  0.557, 0.025, 0.428, 0.95 ,true, _panel.vehicles)
		guiGridListAddColumn ( _panel.grid_vehicles_2 , 'All Vehicles', 0.8 )
				for i=400,611 do
					local v = getVehicleNameFromModel  ( i )
					if v and v ~= '' then
						local row = guiGridListAddRow (_panel.grid_vehicles_2 )
						guiGridListSetItemText ( _panel.grid_vehicles_2, row, 1,v, false, false )
					end	
				end
		_panel.b_add = guiCreateButton ( 0.475, 0.3, 0.05, 0.1, "<", true, _panel.vehicles )
		_panel.b_remove = guiCreateButton ( 0.475, 0.5, 0.05, 0.1, ">", true, _panel.vehicles )
		_panel.close = guiCreateButton ( 0.945, 0.063, 0.06, 0.064, "X", true, _panel.window )
				for k,v in pairs( _panel) do
					if string.find(k,'grid_') then
					guiGridListSetSortingEnabled ( v, false )
					end
				end	
	  addEventHandler( "onClientGUIDoubleClick", getRootElement(), _panel_double_click )
	   addEventHandler ( "onClientGUIClick", getRootElement(), _panel_click)
	   addEventHandler ( "onClientGUIComboBoxAccepted", getRootElement(), _panel_click)
	   showCursor(true)
	   callServer("_panel_load",localPlayer,false)	
		if _panel.read_only == true then
			guiSetEnabled (_panel.b_save, false )
			guiSetEnabled ( _panel.b_save_as , false )
			guiSetEnabled ( _panel.b_delete, false )
			guiSetEnabled ( _panel.c_confings, false )
			guiSetEnabled ( _panel.players, false )
			guiSetEnabled ( _panel.b_balance , false )
			guiSetEnabled ( _panel.b_switch, false )
			guiSetEnabled ( _panel.b_reset, false )
			guiSetEnabled ( _panel.c_confings, false )
			guiSetEnabled ( _panel.b_add, false )
			guiSetEnabled ( _panel.b_remove, false )
			guiSetEnabled ( _panel.grid_weapons_2, false )
			guiSetEnabled ( _panel.grid_teams2, false )
			guiSetEnabled ( _panel.grid_settings, false )
		end
	end
	
	function playerPressedKey(button, press)
		if press and button == 't' or button == 'y'  then
			toggleControl ( 'chatbox',false )
			setTimer(function() toggleControl ( 'chatbox',true ) end,50,1)
		end
	end

	
	
	function _panel_double_click()
		if source ~= _panel.grid_teams and source ~= _panel.grid_vehicles_1 and source ~= _panel.grid_vehicles_2 and source ~= _panel.grid_weapons_1 and source ~= _panel.grid_players then
			for k,v in pairs( _panel) do
				if v == source then
					_panel_edit_window(v)
					return false
				end
			end	
		end	
	end
	
	function load_team_settings()
	local row, column = guiGridListGetSelectedItem ( _panel.grid_teams )
		if row ~= -1 then
		local name = guiGridListGetItemText ( _panel.grid_teams, row, column )	
		local m_fix = {[TableTeams[1]]=1,[TableTeams[2]]=2}
			for k,v in pairs( _panel.teams_l[  m_fix[getTeamFromName( name )] ] ) do
				for i=0, guiGridListGetRowCount ( _panel.grid_teams2 )-1 do
					if k == guiGridListGetItemText (  _panel.grid_teams2, i, 1 ) then
						guiGridListSetItemText ( _panel.grid_teams2, i, 2, v, false, false )
						if k == 'Score' then
							guiGridListSetItemText ( _panel.grid_teams2, i, 2, getElementData ( getTeamFromName( name ),"Score" )	, false, false )
						elseif k == 'Color' then
							guiGridListSetItemColor (  _panel.grid_teams2, i, 2, gettok (v, 1, string.byte(',')),gettok (v, 2, string.byte(',')),gettok (v, 3, string.byte(',')))
						end
					end
				end	
			end	
		end		
	end
	
	function load_weapon_settings()
	local row, column = guiGridListGetSelectedItem ( _panel.grid_weapons_1 )
		if row ~= -1 then
			local name = guiGridListGetItemText ( _panel.grid_weapons_1, row, column )	
			for k,v in pairs( _panel.weapons_l[ getWeaponIDFromName (name) ] ) do
				for i=0, guiGridListGetRowCount ( _panel.grid_weapons_2 )-1 do
					if k == guiGridListGetItemText (  _panel.grid_weapons_2, i, 1 ) then
						guiGridListSetItemText ( _panel.grid_weapons_2, i, 2, v, false, false )
					end
				end	
			end	
		end	
	
	end
	
	function _panel_edit_window(element)
	if guiGetEnabled  ( element ) == true and getElementType ( element ) ==  'gui-gridlist' then
		local row, column = guiGridListGetSelectedItem ( element )
			if row ~= -1 then
				local data  = {guiGridListGetItemText ( element, row, column ),guiGridListGetItemText ( element, row, column+1 )}
				_panel.edit = {set={element,row, column+1,data[1]}}		
					if data[1] == 'Crouch Bug' or data[1] == 'Primary weapon' or data[1] == 'Secondary weapon' or data[1] == 'Special weapon' or data[1] == 'Anti Helli Kill' or data[1] == 'Anti Car Kill' or data[1] == 'Anti Cheat' or data[1] == 'Enable Knife' or data[1] == 'Hide Health' or data[1] == 'Auto Puase' then
						local s_t = {['Crouch Bug']={'alternative','on','default','off'},['Primary weapon']={'true','false'},['Secondary weapon']={'true','false'},['Special weapon']={'true','false'},['Anti Helli Kill']={'true','false'},['Anti Cheat']={'simple','simple with notifications','full','extreme'},['Anti Car Kill']={'true','false'},['Enable Knife']={'true','false'},['Hide Health']={'true','false'},['Auto Puase']={'true','false'}}
							for i=1,#s_t[data[1]] do
								if data[2] == s_t[data[1]][i] then
									if i == #s_t[data[1]] then
										guiGridListSetItemText (_panel.edit.set[1],_panel.edit.set[2],_panel.edit.set[3],s_t[data[1]][1],false ,false)
										_panel_update_table( element,data[1],s_t[data[1]][1])
									else
										guiGridListSetItemText (_panel.edit.set[1],_panel.edit.set[2],_panel.edit.set[3],s_t[data[1]][i+1],false ,false)
										_panel_update_table( element,data[1],s_t[data[1]][i+1])
									end
										
									break
								end
							end
						return false
					end
				guiSetPosition ( _panel.window,1,1,true )
				addEventHandler("onClientKey", getRootElement(), playerPressedKey)
				_panel.edit.window = guiCreateWindow ((screenWidth-300)/2, (screenHeight-100)/2, 300, 100, "A/D Aspect 1.0.6: Edit Window.",false )
				_panel.edit.text = guiCreateLabel (0.05, 0.35 , 0.4, 0.2, tostring(data[1])..':', true, _panel.edit.window )
				guiSetFont ( _panel.edit.text,myFont )
				local add = getRelativeByScreenPositionViaElement(guiLabelGetTextExtent ( _panel.edit.text ),0,_panel.edit.window) 
				_panel.edit.edit = guiCreateEdit ( 0.1+add, 0.3, 0.4, 0.2, tostring(data[2]), true, _panel.edit.window )
				_panel.edit.ok = guiCreateButton ( 0.1, 0.65, 0.35, 0.2, "Ok", true,_panel.edit.window )
				_panel.edit.cencel = guiCreateButton ( 0.55, 0.65, 0.35, 0.2, "Cancel", true ,_panel.edit.window )
				
			end
		end	
	end
	
	function _panel_edit_window_(element,player,title,function_)
		local string_ = guiGetText(element)
		_panel.edit_ = {element,player,title,function_}
		guiSetPosition ( _panel.window,1,1,true )
		addEventHandler("onClientKey", getRootElement(), playerPressedKey)
		_panel.edit_.window_ = guiCreateWindow ((screenWidth-300)/2, (screenHeight-100)/2, 300, 100, "A/D Aspect 1.0.6: Edit Window.",false )
		_panel.edit_.text_ = guiCreateLabel (0.05, 0.35 , 0.4, 0.2, tostring(title), true, _panel.edit_.window_ )
		guiSetFont ( _panel.edit_.text_,myFont )
		local add = getRelativeByScreenPositionViaElement(guiLabelGetTextExtent ( _panel.edit_.text_ ),0,_panel.edit_.window_) 
		_panel.edit_.edit_ = guiCreateEdit ( 0.1+add, 0.3, 0.4, 0.2, '', true, _panel.edit_.window_ )
		_panel.edit_.ok_ = guiCreateButton ( 0.1, 0.65, 0.35, 0.2, "Ok", true,_panel.edit_.window_ )
		_panel.edit_.cencel_ = guiCreateButton ( 0.55, 0.65, 0.35, 0.2, "Cancel", true ,_panel.edit_.window_ )
		
	end
	
	function _panel_save_as(n_n)
		guiSetPosition ( _panel.window,1,1,true )
		_panel.save = {}
		addEventHandler("onClientKey", getRootElement(), playerPressedKey)
		_panel.save.window = guiCreateWindow ((screenWidth-300)/2, (screenHeight-100)/2, 300, 100, "A/D Aspect 1.0.6: Save as.",false )
		_panel.save.text = guiCreateLabel (0.05, 0.35 , 0.4, 0.2, 'Name:', true, _panel.save.window )
		guiSetFont ( _panel.save.text,myFont )
		local add = getRelativeByScreenPositionViaElement(guiLabelGetTextExtent ( _panel.save.text ),0,_panel.save.window) 
		_panel.save.edit = guiCreateEdit ( 0.1+add, 0.3, 0.4, 0.2, n_n or _panel.current or '', true, _panel.save.window )
		_panel.save.ok = guiCreateButton ( 0.1, 0.65, 0.35, 0.2, "Ok", true,_panel.save.window )
		_panel.save.cencel = guiCreateButton ( 0.55, 0.65, 0.35, 0.2, "Cancel", true ,_panel.save.window )
	end
	
	function _panel_update_table(grid,index,value)
		if grid == _panel.grid_weapons_2  then
			local row, column = guiGridListGetSelectedItem ( _panel.grid_weapons_1 )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_weapons_1, row, column )	
					_panel.weapons_l[ getWeaponIDFromName (name) ][index] = value
				end
		elseif grid == _panel.grid_teams2  then	
			local row, column = guiGridListGetSelectedItem ( _panel.grid_teams )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_teams, row, column )	
						local m_fix = {[TableTeams[1]]=1,[TableTeams[2]]=2}
					_panel.teams_l[ m_fix [getTeamFromName( name )] ][index] = value
					if index == 'Score' then
						setElementData ( getTeamFromName( name ),"Score",tonumber(value)  )	 
					end
				
				end	
		end
		
	end
	
	function _panel_click()
		if source == _panel.save.ok then
			local data = guiGetText ( _panel.save.edit )
			if #data == 0 then
				outputChatBox ( "#FF0000** Error:#0AC419 You must enter your config name.", 255, 255, 255, true )
				return false
			end	
			_panel_save(data)
			destroyElement(_panel.save.window)
			guiSetPosition (_panel.window, (screenWidth-550)/2, (screenHeight-350)/2,false )
			_panel.save = {}
			removeEventHandler("onClientKey", getRootElement(), playerPressedKey)
			guiBringToFront ( _panel.window )
		elseif source == _panel.save.cencel then
			destroyElement(_panel.save.window)
			guiSetPosition (_panel.window, (screenWidth-550)/2, (screenHeight-350)/2,false )
			_panel.save = {}
			removeEventHandler("onClientKey", getRootElement(), playerPressedKey)
			toggleControl ( 'chatbox',true )
			guiBringToFront ( _panel.window )
		elseif source == _panel.edit.ok then
			local data = guiGetText ( _panel.edit.edit )
				if _panel.edit.set[4] == 'Skin' and isNot( tonumber( data ) ) == false then
					outputChatBox ( "#FF0000** Error:#0AC419 This skin is blocked ( too small size ), select other or click cancel.", 255, 255, 255, true )
					return false
				elseif _panel.edit.set[4] == 'Maximal ping' and 550 <  tonumber( data )  then
					outputChatBox ( "#FF0000** Error:#0AC419 Maximal ping can't be higher than 550, sorry.", 255, 255, 255, true )
					return false
				elseif _panel.edit.set[4] == 'Minimal fps' and 25 > tonumber( data ) then	
					outputChatBox ( "#FF0000** Error:#0AC419 Minimal fps can't be smaller than 25, sorry.", 255, 255, 255, true )
					return false				
				elseif _panel.edit.set[4] == 'Maximal packet loss' and  tonumber( data ) > 10 then	
					outputChatBox ( "#FF0000** Error:#0AC419 Maximal packet loss can't be higher than 10%, sorry.", 255, 255, 255, true )
					return false
				end
			guiGridListSetItemText (_panel.edit.set[1],_panel.edit.set[2],_panel.edit.set[3],data,false ,false)
			_panel_update_table( _panel.edit.set[1],_panel.edit.set[4],data)
			destroyElement(_panel.edit.window)
			guiSetPosition (_panel.window, (screenWidth-550)/2, (screenHeight-350)/2,false )
			_panel.edit = {}
			removeEventHandler("onClientKey", getRootElement(), playerPressedKey)
			guiBringToFront ( _panel.window )
		elseif source == _panel.edit.cencel then
			destroyElement(_panel.edit.window)
			guiSetPosition (_panel.window, (screenWidth-550)/2, (screenHeight-350)/2,false )
			_panel.edit = {}
			removeEventHandler("onClientKey", getRootElement(), playerPressedKey)
			guiBringToFront ( _panel.window )
		elseif source == _panel.edit_.cencel_ then
			destroyElement(_panel.edit_.window_)
			guiSetPosition (_panel.window, (screenWidth-550)/2, (screenHeight-350)/2,false )
			_panel.edit_ = {}
			guiBringToFront ( _panel.window )
		elseif source == _panel.edit_.ok_ then
			local data = guiGetText ( _panel.edit_.edit_ )
				if _panel.edit_[4] == 'kickPlayer' then
					callServer("kickPlayer",_panel.edit_[2],localPlayer,data) 
				elseif _panel.edit_[4] == 'banPlayer' then
					callServer("banPlayer",_panel.edit_[2],false,false,true,localPlayer,data) 
				elseif _panel.edit_[4] == 'setPlayerName' then
					callServer("setPlayerName",_panel.edit_[2],data) 
				end
			destroyElement(_panel.edit_.window_)
			guiSetPosition (_panel.window, (screenWidth-550)/2, (screenHeight-350)/2,false )
			_panel.edit_ = {}
			guiBringToFront ( _panel.window )
		elseif source == _panel.b_add then
			local row, column = guiGridListGetSelectedItem ( _panel.grid_vehicles_2 )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_vehicles_2, row, column )
					guiGridListRemoveRow ( _panel.grid_vehicles_2, row )
					local row2 = guiGridListAddRow (_panel.grid_vehicles_1 )
					guiGridListSetItemText ( _panel.grid_vehicles_1, row2, 1,name, false, false )
				end
		elseif source == _panel.b_remove then
			local row, column = guiGridListGetSelectedItem ( _panel.grid_vehicles_1 )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_vehicles_1, row, column )
					guiGridListRemoveRow ( _panel.grid_vehicles_1, row )
					local row2 = guiGridListAddRow (_panel.grid_vehicles_2 )
					guiGridListSetItemText ( _panel.grid_vehicles_2, row2, 1,name, false, false )
				end
		elseif source == _panel.grid_weapons_1  then
			load_weapon_settings()
		elseif source == _panel.b_balance  then	
		elseif source == _panel.b_switch  then	
			callServer('ChangeTeamAllPpl')		
		elseif source == _panel.b_reset  then	
			callServer('resetscore_cmd',localPlayer)	
		elseif source == _panel.close  then	
			showCursor(false)
			destroyElement(_panel.window)
			destroyElement(_panel.info)
			removeEventHandler( "onClientGUIDoubleClick", getRootElement(), _panel_double_click )
			removeEventHandler ( "onClientGUIClick", getRootElement(), _panel_click)
			removeEventHandler ( "onClientGUIComboBoxAccepted", getRootElement(), _panel_click)
			_panel = {}
		elseif source == _panel.b_delete  then	
			if _panel.current ~= 'default' then
				callServer("_panel_delete",localPlayer,guiComboBoxGetItemText ( _panel.c_confings ,guiComboBoxGetSelected ( _panel.c_confings )))	
			end
		elseif source == _panel.b_save  then
			if _panel.current == 'default' then
				_panel_save_as('')	
			else
				_panel_save(_panel.current)
			end	
		elseif source == _panel.b_save_as  then	
			_panel_save_as()	
		elseif source == _panel.grid_teams  then		
				load_team_settings()
		elseif source == _panel.grid_players  then	
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								callServer("_pane_player_tab",localPlayer,name,player) 
							end	
				end	
		elseif source == _panel.memo_players then
			setClipboard ( guiGetText( _panel.memo_players ) )
			outputConsole (  '\n\n'..guiGetText( _panel.memo_players )..'\n\n')
		elseif source == _panel.c_confings then
			guiSetAlpha ( _panel.window, 0 )
			guiSetAlpha ( _panel.info, 1 )
			callServer("_panel_load",localPlayer,guiComboBoxGetItemText ( _panel.c_confings ,guiComboBoxGetSelected ( _panel.c_confings )))	
		elseif source == _panel.b_kick then	
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								_panel_edit_window_(source,player,'Kick reason:','kickPlayer')
							end	
				end		
		elseif source == _panel.b_ban then
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								_panel_edit_window_(source,player,'Ban reason:','banPlayer')
							end	
				end	
		elseif source == _panel.b_name then
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								_panel_edit_window_(source,player,'New name:','setPlayerName')
							end	
				end	
		elseif source == _panel.b_team then
				local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								guiSetPosition ( _panel.window,1,1,true )
								change_team_window(player)
							end	
				end	
		elseif source == _panel.b_add_ then
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								callServer("add_cmd",localPlayer,'add',getElementData(player,'ID'))	
							end	
				end	
		elseif source == _panel.b_restore then
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								restore_window_request('restore',getElementData(player,'ID'))
							end	
				end
		elseif source == _panel.b_remove_ then
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								callServer("remove_cmd",localPlayer,'remove',getElementData(player,'ID'))	
							end	
				end			
		elseif source == _panel.b_heal then
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								callServer("heal",localPlayer,'heal',getElementData(player,'ID'))	
							end	
				end			
		elseif source == _panel.b_gun then
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								callServer("gunmenu_cmd",localPlayer,'gunmenu',getElementData(player,'ID'))	
							end	
				end				
		elseif source == _panel.b_healall then
			local row, column = guiGridListGetSelectedItem (_panel.grid_players )
				if row ~= -1 then
					local name = guiGridListGetItemText ( _panel.grid_players, row, column )
						local player = getPlayerFromName(name)
							if player then
								callServer("healall",localPlayer,'healall',getElementData(player,'ID'))	
							end	
				end			
		end
	end	
	
	function _pane_player_tab(name,player,serial,ping,hp,version,ip)

		if getPedOccupiedVehicle ( player ) == false then
			guiSetText ( _panel.memo_players, 'Name: '..name..'\nIP: '..ip..'\nSerial: '..serial..'\nVersion: '..version..'\nPing: '..ping..'\nHP: '..getElementHealth(player))
		else
			guiSetText ( _panel.memo_players, 'Name: '..name..'\nIP: '..ip..'\nSerial: '..serial..'\nVersion: '..version..'\nPing: '..ping..'\nHP: '..getElementHealth(player)..'\nVehicle: '..getVehicleName(getPedOccupiedVehicle ( player ))..'( '..math.round(getElementHealth (getPedOccupiedVehicle ( player )),0)..' )')
		end
	end
	
	function _panel_save(name)
	local table_to_send = { weapons=_panel.weapons_l,teams_l=_panel.teams_l,global={},vehicles={}}
		for i=0, guiGridListGetRowCount ( _panel.grid_settings )-1 do
			table_to_send.global[guiGridListGetItemText ( _panel.grid_settings, i, 1 )] = guiGridListGetItemText ( _panel.grid_settings, i, 2 )
		end
		for i=0, guiGridListGetRowCount ( _panel.grid_vehicles_1 )-1 do
			table.insert(table_to_send.vehicles,guiGridListGetItemText ( _panel.grid_vehicles_1, i, 1 ))
		end
	callServer("_panel_save",localPlayer,name, table_to_send)		
	end
	
	function _panel_load(table_,confings, name)
		destroyElement(_panel.c_confings)
		_panel.c_confings = guiCreateComboBox ( 0.01, 0.06, 0.25, 0.5, name ,true, _panel.window )
		if _panel.read_only == true then
			guiSetEnabled ( _panel.c_confings, false )
		end
		
		_panel.current = name
		for k,v in pairs( confings ) do
			guiComboBoxAddItem(_panel.c_confings, v )
		end
		guiGridListClear ( _panel.grid_vehicles_1 )
		for k,v in pairs( table_.vehicles ) do
			local row = guiGridListAddRow (_panel.grid_vehicles_1 )
			guiGridListSetItemText ( _panel.grid_vehicles_1, row, 1, v, false, false )
		end	
		for k,v in pairs( table_.global ) do
			for i=0, guiGridListGetRowCount ( _panel.grid_settings )-1 do
				if k == guiGridListGetItemText (  _panel.grid_settings, i, 1 ) then
					guiGridListSetItemText (  _panel.grid_settings, i, 2, v, false, false )
				end
			end	
		end
		_panel.weapons_l = {}
		for k, v in pairs ( table_.weapons ) do
			_panel.weapons_l[tonumber(k)] = v
		end	
		_panel.teams_l = {}
		for k, v in pairs ( table_.teams_l ) do
			_panel.teams_l[tonumber(k)] = v
		end	
			guiGridListClear ( _panel.grid_teams )
			local settings_l ={getTeamName(TableTeams[1]),getTeamName(TableTeams[2])}
				for k,v in ipairs(settings_l) do
					local row = guiGridListAddRow (_panel.grid_teams )
					guiGridListSetItemText ( _panel.grid_teams, row, 1, v, false, false )
				end
			guiGridListSetSelectedItem ( _panel.grid_teams, 0, 1)	
			load_team_settings()
			guiGridListSetSelectedItem ( _panel.grid_weapons_1, 0, 1)	
			load_weapon_settings()
			
		guiSetAlpha ( _panel.window, 1 )
		guiSetAlpha ( _panel.info, 0 )
		guiBringToFront ( _panel.window )
	end


function loadGameSettings(t)
	game_settings = t
end

function updateResolution()
local x,y = guiGetScreenSize ()
setElementData ( localPlayer,"Resoultion",tostring(x).."x"..tostring(y)) 
end
local wasted_t = {speed = 1,granade=getTickCount()}
function opws(weapon)
    if weapon == 16 then 
       wasted_t.granade = getTickCount()
    end
end
addEventHandler("onClientPlayerWeaponFire", localPlayer, opws)

function getAnimBlock(block,id)
	local anim_blocks ={
		su = {
		{'CRACK','crckdeth1',0.05},
		{'CRACK','crckdeth2',0.05},
	--	{'BEACH','Lay_Bac_Loop',0.05},
		},
		normal = {
		{'FIGHT_C','HitC_3',0.05},
		{'FIGHT_D','HitC_D',0.05},
		{'CHAINSAW','CSAW_Hit_3',0.05},
		{'BASEBALL','Bat_Hit_3',0.05},
		{'DILDO','DILDO_Hit_3',0.05},
		{'KNIFE','knife_hit_3',0.05},
		{'FIGHT_E','Hit_fightkick_B',0.05},
		{'ped','KO_shot_stom',0.05},
		{'ped','KO_skid_front',0.05},
		{'FIGHT_B','HitB_3',0.2},
		},
		grenade = {
		{'FIGHT_C','HitC_3',0.05},
		{'FIGHT_D','HitC_D',0.05},
		{'FIGHT_E','Hit_fightkick_B',0.05},
		{'FIGHT_B','HitB_3',0.2},
		}
	}
	return anim_blocks[block][id]
end	
local death_cam_t = {anim={}}

function projectileCreation()
		death_cam_t.project  = source
end
addEventHandler("onClientProjectileCreation", getRootElement(), projectileCreation)

function wastedMessage ( killer, weapon, bodypart )
	if getElementData ( localPlayer,"IsSpawned" ) == 1 and  getElementData ( sett,"Round" ) ~= 0 and getPlayerTeam( localPlayer ) ~= TableTeams[3] then
	setElementAlpha(localPlayer,0)
	local x,y,z = getElementPosition(localPlayer)
	death_cam_t.vel = {getElementVelocity(localPlayer)}
	death_cam_t.ped = createPed( getElementModel( localPlayer),x,y,z+0.075)
	setElementCollisionsEnabled ( death_cam_t.ped, false )
	setElementCollidableWith ( death_cam_t.ped, localPlayer, false )
	setElementCollidableWith ( localPlayer, death_cam_t.ped ,false )
	death_cam_t.interor = getElementInterior(localPlayer)
		if killer and getElementType(killer ) == 'player' and killer ~= localPlayer then
			local kX,Ky,Kz = getElementPosition(killer)
				if weapon == 16 or  weapon == 51 then 
					death_cam_t.anim = getAnimBlock('grenade',math.random(1,4))
						if isElement( death_cam_t.project ) then
							kX,Ky,Kz = getElementPosition(death_cam_t.project)
						end
				else
					death_cam_t.anim = getAnimBlock('normal',math.random(1,10))
				end
			death_cam_t.rot = findRotation(x,y, kX,Ky)
		else
			death_cam_t.anim = getAnimBlock('su',math.random(1,2))
			death_cam_t.rot = getPedRotation(localPlayer)
			local x,y,z = getElementPosition(death_cam_t.ped)
			setElementPosition( death_cam_t.ped,x,y,z+0.06)
		end
		death_cam_t.tick = getTickCount()
		addEventHandler( "onClientElementStreamIn", death_cam_t.ped,sasadds)
	end
end
addEventHandler ( "onClientPlayerWasted", localPlayer, wastedMessage )

function sasadds()
	setElementCollisionsEnabled ( death_cam_t.ped, false )
	setElementCollidableWith ( death_cam_t.ped, localPlayer, false )
	setElementCollidableWith ( localPlayer, death_cam_t.ped ,false )
	setElementInterior( death_cam_t.ped,death_cam_t.interor)
	local x,y,z = getElementPosition(death_cam_t.ped)
	setElementPosition( death_cam_t.ped,x,y,z+0.135)
	removeEventHandler( "onClientElementStreamIn", death_cam_t.ped,sasadds)
	setElementVelocity(death_cam_t.ped, unpack(death_cam_t.vel))
	setPedRotation(death_cam_t.ped,death_cam_t.rot)
				wasted_t.speed = death_cam_t.anim[3]
				wasted_t.speed2 = 0.0
				death_cam_t.pos = {getCameraMatrix()}
				death_cam_t.rot = getPedCameraRotation (localPlayer)
				death_cam_t.rotAdd = 90
				setPedAnimation(death_cam_t.ped,death_cam_t.anim[1],death_cam_t.anim[2],5000,false,true,true,true)
				addEventHandler("onClientRender", getRootElement(),render_death_cam_fade) 
end

function render_death_cam_fade()
	local x,y,z = getElementPosition(death_cam_t.ped)
	local poss = {}
	poss[1]={PobierzPozycjeKamery( x,y,z,death_cam_t.rot+death_cam_t.rotAdd ,2.5 )	}
	poss[2]={PobierzPozycjeKamery( x,y,z,death_cam_t.rot+death_cam_t.rotAdd ,2)}
	death_cam_t.rotAdd=death_cam_t.rotAdd+0.5
	setCameraMatrix( poss[1][1],poss[1][2],poss[1][3],poss[2][1],poss[2][2],poss[2][3])
	wasted_t.speed =wasted_t.speed +  0.001 + wasted_t.speed2
	wasted_t.speed2 = wasted_t.speed2+0.0001
	if wasted_t.speed > 1 then
		wasted_t.speed = 1
		setPedAnimationProgress ( death_cam_t.ped,death_cam_t.anim[2],wasted_t.speed)
		removeEventHandler("onClientRender", getRootElement(),render_death_cam_fade)
			if getTickCount() - death_cam_t.tick > 5000 then
				destroyElement(death_cam_t.ped)
				death_cam_t = {anim={}}
			else
				setTimer(function()
						destroyElement(death_cam_t.ped)
						death_cam_t = {anim={}}
				end, 5000- (getTickCount() - death_cam_t.tick) or 1000,1)
			end
	end
	setPedAnimationProgress ( death_cam_t.ped,death_cam_t.anim[2],wasted_t.speed)
	

end

function render_death_cam_rage_delete()
	if death_cam_t.ped then
		removeEventHandler("onClientRender", getRootElement(),render_death_cam_fade)
		removeEventHandler("onClientRender", getRootElement(),render_death_cam)
		destroyElement(death_cam_t.ped)
		death_cam_t = {anim={}}
	end	
end

function render_death_cam()

	wasted_t.speed =wasted_t.speed -0.075
	if wasted_t.speed < 0.1 then
		wasted_t.speed = 0.05
		removeEventHandler("onClientRender", getRootElement(),render_death_cam)
	end
	setGameSpeed(wasted_t.speed)

end

local dmg_draw = {alpha=0,sens=0.5,add=0.01,state = false }
function damage_animation(loss)
	local sensitive = math.max(0.15,math.min(0.65,(loss/2)*0.035))
		dmg_draw = {alpha=0,sens=sensitive,add=0.025,state = true}
	addEventHandler("onClientRender", getRootElement(),damage_animation_draw)
end

function onClientPlayerDamage_hitanim ( attacker, weapon, bodypart, loss )
	if dmg_draw.state == false then
			if client_settings[17] == 'true' then
				damage_animation(loss)
			end	
	end
end
addEventHandler ( "onClientPlayerDamage", localPlayer,  onClientPlayerDamage_hitanim)

function damage_animation_draw()
dmg_draw.alpha = dmg_draw.alpha +dmg_draw.add
	if dmg_draw.alpha > dmg_draw.sens then
		dmg_draw.add=-0.01 
	end	
	if dmg_draw.add== -0.01 and dmg_draw.alpha < 0.02 then
		removeEventHandler("onClientRender", getRootElement(),damage_animation_draw)
		dmg_draw.state = false
	end
--dxDrawRectangle ( 0, 0, screenWidth, screenHeight , tocolor(255,25,25,255*dmg_draw.alpha))
dxDrawImage (  0, 0, screenWidth, screenHeight, "img/blood.png" ,0, 0,  0,  tocolor(255,255,255,255*dmg_draw.alpha))
end

function playSound3DHelp ( soundPath, x,y, z )
	local s = playSound3D ( soundPath, x,y, z)
	setSoundMinDistance ( s, 1000 )
	setSoundMaxDistance ( s, 1000 )
end

local callhelpLast = getTickCount()
function callHelp()
		if getElementData ( localPlayer,"IsSpawned" ) == 0  then
		return false
	end 
	if (getTickCount() - callhelpLast) >  15000 then
		callhelpLast = getTickCount()
		callServer("callHelp", localPlayer)
	else
		outputChatBox ( "#FF0000** Error:#0AC419 You can only use this command once every 15 seconds.", 255, 255, 255, true )
	end
end

function render2()
	local wtf = {'fire','next_weapon','previous_weapon','sprint','crouch','aim_weapon'}
	local wsdsd = ''
		for k,v in ipairs(wtf) do 
			if getControlState ( v ) then
				wsdsd = wsdsd.. '\n [['..v..']]'
			end
		end
		setElementData( localPlayer ,'cstats',wsdsd )
end
--addEventHandler("onClientRender", getRootElement(), render2)
function render()
	local players = getElementsByType ( "player",getRootElement(),true)
		for k,v in ipairs(players) do 
			if v ~= localPlayer then
				local x,y,z = getPedBonePosition ( v, 22)
				local w, s = getScreenFromWorldPosition (  x,y,z , 10,false )
				if w and s then
					local ws = getElementData( v ,'cstats' )
					dxDrawText ( ws, w, s )
				end
			end	
		end
end
--addEventHandler("onClientRender", getRootElement(), render)

--///////////////SPECTATOR///////////////////

m,s = 0,0
CoundTownT = nil
ActuallySpec = nil
draw_t = {color = tocolor(255,5,5,255),size = 8,mn=2,max=25}
T_table_info = {}
P_t_info = {}
addEvent ( "RemoveSpectateMode", true )
addEvent ( "AddSpectateMode", true )


colors_t = {team1=tocolor(255,0,50,255),team2=tocolor(0,255,50,255),gold=tocolor(238,180,34,255),gray=tocolor(200,200,200,255),green=tocolor(100,180,34,255),lgreen=tocolor(90,205,25),green2=tocolor( 65 ,105, 225),black=tocolor(0,0,0,255),gray2=tocolor( 25 ,24 ,24)}
_t_i = {}
 t_c = {}
 SpectGui_t = {}
setTimer(function()
		_t_i[1] = getTeamByType("Attack")
		_t_i[2] = getTeamByType("Defense")
		_t_i[_t_i[1]] = "Att"
		_t_i[_t_i[2]] = "Def"
		t_c[_t_i[1]] = getTeamName(_t_i[1])
		t_c[_t_i[2]]=getTeamName(_t_i[2])
		T_table_info[_t_i[1]] = {}
		T_table_info[_t_i[2]] = {}
		T_table_info[_t_i[1]]["Active_Players"] = tostring(getElementData(_t_i[1],"Active_Players"))
		T_table_info[_t_i[1]]["Score"] = tostring(getElementData(_t_i[1],"Score"))
		T_table_info[_t_i[1]]["Health"] = tostring(getElementData(_t_i[1],"Health"))
		T_table_info[_t_i[2]]["Active_Players"] = tostring(getElementData(_t_i[2],"Active_Players"))
		T_table_info[_t_i[2]]["Score"] = tostring(getElementData(_t_i[2],"Score"))
		T_table_info[_t_i[2]]["Health"] = tostring(getElementData(_t_i[2],"Health"))
		P_t_info = {Health="100%",Team ="",Kills = tostring(getElementData(LocalPlayer,"Kills")),Deaths = tostring(getElementData(LocalPlayer,"Deaths")),RoundName = tostring(getElementData(sett,"RoundName")),RoundInt = tostring(getElementData(sett,"RoundInt"))}
end,500,1)		
t2 = "Def"

function UpdateOnOneTeam(dataName)
	if getElementType(source) == "team" then
		if dataName == "Active_Players" or dataName == "Score" or dataName == "Health" then
			if game_settings.global[4] == 'true' and dataName == "Health" then
				T_table_info[source][dataName] = ' - '
				return false
			end
		T_table_info[source][dataName] = tostring(getElementData(source,dataName))
		--UpdateProgressBar(Hud_data[source][dataName.."_p"],Hud_data[source][dataName] ,8,10)
		end
	end	
end
addEventHandler ( "onClientElementDataChange",getRootElement(),UpdateOnOneTeam	)

function UpdateOnPlayer(dataName,old)
	if source == LocalPlayer then
		if dataName == "Kills" or dataName == "Deaths" then
			local ret = getElementData(source,dataName)
			P_t_info[dataName] = tostring(ret)
			if ret ~= 0 then
				local f = {Kills=14,Deaths=15}
				client_settings[f[dataName]] = tonumber( client_settings[f[dataName]] ) +1
			end
		elseif dataName == "Damage" and getElementData(source,dataName) ~= 0 then
			client_settings[16] = tonumber( client_settings[16] ) + (  getElementData(source,dataName)  - ( old or 0) )
		elseif dataName == "Health" then
			local d = tostring(getElementData(source,dataName))
			if d == "Protect" then d = "100" end
			P_t_info[dataName] = d.."%"
		end
	elseif source == sett then
		if dataName == "RoundName" or dataName == "RoundInt" then
			P_t_info[dataName] = tostring(getElementData(source,dataName))
				if dataName == "RoundName" then
				P_t_info[dataName] = string.upper(string.sub(P_t_info[dataName] , 0,1)).. string.sub(P_t_info[dataName] , 2,string.len( P_t_info[dataName]))..":"
				end
		end
	P_t_info.Team = tostring(getTeamName(getPlayerTeam(getLocalPlayer())))
	end	
end
addEventHandler ( "onClientElementDataChange",getRootElement(),UpdateOnPlayer	)

local freeCameraModes = {"All Teams","Team1","Team2"}
local freeCameraTypes = {"Normal","Free Camera"}
function OnPlayerWantSelectOnNewMenu()
	if ElementData[source] ~= nil then
		if ElementData[source] == "img1" or ElementData[source] == "img2" then
		local f ={["img1"]=1,["img2"]=2}
			if SpectGui_t["Grid"..f[ElementData[source]]] == nil then
				local x,y = guiGetPosition ( SpectGui_t["button"..f[ElementData[source]]]  , true )
				local Sx,Sy = guiGetSize ( SpectGui_t["button"..f[ElementData[source]]]  , true )
				SpectGui_t["Grid"..f[ElementData[source]]] = CreateGridListTosel(x, y-(Sy*5.3), Sx, Sy*5,GetTableToSelect(f[ElementData[source]]))
				addEventHandler ( "onClientGUIClick", SpectGui_t["Grid"..f[ElementData[source]]], OnElementSelect, false )
			else
				destroyElement(SpectGui_t["Grid"..f[ElementData[source]]])
				SpectGui_t["Grid"..f[ElementData[source]]] = nil
			end
		end
	end
end	

function GetTableToSelect(grid)
local ret_t 
	if grid == 1 then
	local g_ = GetSpectateMode(getSpectateType(getPlayerTeam(getLocalPlayer())),"allow_teams")
		if g_ == "all" then
		ret_t = {"All teams",getTeamName(getTeamByType("Attack")),getTeamName(getTeamByType("Defense"))}
		else
		ret_t = {getTeamName(getPlayerTeam(getLocalPlayer()))}
		end
	elseif grid == 2 then
	local g_ = GetSpectateMode(getSpectateType(getPlayerTeam(getLocalPlayer())),"free")
		if g_ == true then
		ret_t = {"Normal","Free Cam"}
		else
		ret_t = {"Normal"}
		end
	end
	return ret_t
end



function OnElementSelect()
local select = guiGridListGetSelectedItem ( source )
	if select ~= -1 then
		playSoundFrontEnd ( 2 )
		local primarySelection = guiGridListGetItemText ( source, select , 1 )
		for i=1,3 do 
			if source == SpectGui_t["Grid"..i] then
			guiSetText(SpectGui_t["button"..i],primarySelection)
			removeEventHandler ( "onClientGUIClick", SpectGui_t["Grid"..i], OnElementSelect, false )
			destroyElement(SpectGui_t["Grid"..i])
			SpectGui_t["Grid"..i] = nil
			UpdateCameraOpts(i,primarySelection)
			end
		end
	end
end

function UpdateCameraOpts(grid,option)
	if grid == 1 then
	--	if ActualySpectMode.team ~= option then
		ActualySpectMode.team = option
		UpdateSpectTable(ActualySpectMode.team)
	--	end
	elseif grid == 2 then
		if ActualySpectMode.camera ~= option then
		ActualySpectMode.camera = option
			if ActualySpectMode.camera  == "Free Cam" then
			removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_3)
			call(getResourceFromName("freecam"), "setFreecamOption", "normalMaxSpeed",0.7)
			call(getResourceFromName("freecam"), "setFreecamOption", "fastMaxSpeed ",5)
			call(getResourceFromName("freecam"), "setFreecamEnabled")
			dxDrawTextAlongTime(6*40,screenWidth/3.2, screenHeight/1.25,yhy2(800,1.3),"sans","Press ",colors_t.gray,"Left Alt ",colors_t.gold,"to slow mode camera or ",colors_t.gray,"Lewt Shift",colors_t.gold," to fast mode camera",colors_t.gray)
			else
			call(getResourceFromName("freecam"), "setFreecamDisabled")
			addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_3)
			end
		end
	end
end

function getPlayerIntFromHerName(TenGracz)
	local asd 
	for k,v in pairs(spect_t) do
		if v == TenGracz then
		asd = k
		end
	end	
	return asd
end

function CreateGridListTosel(x,y,sx,sy,table_S)
		local gridList = guiCreateGridList ( x,y,sx,sy, true )
		guiSetAlpha(gridList,0.745)
		guiGridListSetSelectionMode ( gridList, 0 )
        guiGridListAddColumn (gridList , " ", 0.85 )
        for key,weaponName in pairs(table_S) do
		local row = guiGridListAddRow ( gridList )
                guiGridListSetItemText ( gridList, row, 1, weaponName, false, false )
        end
		return gridList
end

local Roznica_s
local Global_T 
local ThisCount_g 
RoundTimer_pause = false
local ovx,ovy,ovz
local rx,ry,rz = 0,0,0
addEvent("CreateRoundTimer",true)
function CreateRoundTimer(asd)
--outputChatBox('timer: '..tostring(asd))
Global_T = asd

getTimeFromMilisec(((Global_T)))
ThisCount_g = getTickCount()
CoundTownT = setTimer(UpdateTime,1000,0)
s_1_00 = false
end
addEventHandler("CreateRoundTimer", getRootElement(), CreateRoundTimer)

function UpdateTime() 
	if RoundTimer_pause == false then
		local cc = getTickCount()
		cc=cc - ThisCount_g
		getTimeFromMilisec(((Global_T)-cc))
	end
	 disable_cheats()
end
local pause_t = {t="|| Pause",pos = {getScreenPositionByRelative(0.4,0.45)},size=2,}

	function disable_cheats()
		for k,v in ipairs({"hovercars","aircars","extrabunny","extrajump"}) do
			if isWorldSpecialPropertyEnabled ( v ) == true then
				setWorldSpecialPropertyEnabled ( v, false)
			end
		end
	end


function renderPuase ()

	dxDrawRectangle (0, 0, screenWidth, screenHeight ,tocolor(0,0,0,120))
	dxDrawText ( pause_t.t,  pause_t.pos[1], pause_t.pos[2] , 0, 0,colors_g.gray, pause_t.size , "bankgothic") 

end

function PauseRound()
	toggleAllControls ( false, true, false )
	Roznica_s = getTickCount()
	RoundTimer_pause = true
	pause_t.t="|| Pause"
	--setTimer(function() addEventHandler("onClientPlayerDamage", getLocalPlayer( ), CancelLef) end,150,1)
	addEventHandler("onClientRender", getRootElement(), renderPuase)
	_game_status = 0
end



function CancelLef()
	cancelEvent()
end
function PreRePauseRound()
	pause_t.t="|Get Ready|"
		setTimer(function()pause_t.t="|> PLAY" end,1000,1)
	setTimer(RePauseRound,2000,1)
end


function RePauseRound()
	if RoundTimer_pause == true then
		toggleAllControls ( true)
		local Roznica_e = getTickCount()
		Global_T = Global_T+(Roznica_e - Roznica_s)
		removeEventHandler("onClientRender", getRootElement(), renderPuase)
		_game_status = 1
		RoundTimer_pause = false
	--removeEventHandler("onClientPlayerDamage", getLocalPlayer( ), CancelLef)
			if isPedInVehicle ( getLocalPlayer( ) ) ==  true then
			local Veh = getPedOccupiedVehicle(getLocalPlayer( ))
				 setElementVelocity(Veh,ovx,ovy,ovz)
			else
				setElementVelocity( getLocalPlayer( ),ovx,ovy,ovz)
			end
	end
end
addEvent("DestroyRoundTimer",true)
function DestroyRoundTimer()
	if isTimer( CoundTownT ) then
		killTimer(CoundTownT)
	end	
	G_hud = FormatTimer(0,0)
end
addEventHandler("DestroyRoundTimer", getRootElement(), DestroyRoundTimer)
G_hud = "0:0"
local s_1_00 = false
function getTimeFromMilisec(t)
	local f = (t/1000)/60
	m = math.modf(f)
	s =  math.modf((f-m)*60)
	G_hud = FormatTimer(m,s)
		if s == 0 then
			if m == 1 and s_1_00 == false then
				s_1_00 = true
				local e_s = playSound("sounds/alarm.ogg",false)
					setSoundVolume( e_s,0.6)
			end
		end
end


local spect_t = {}
local actualyspectInt = 1
local HudVars = {
[1] = {(screenHeight/1.04632), (screenHeight/21.9),"img/health.png"}, -- glowny obrazek wersja dla gracza (y, rozmiar y)
[2] = {(screenHeight/1.154), (screenHeight/7.4564),"img/trans2.png"}, -- glowny obrazek wersja dla obserwatora (y, rozmiar y)
[3] = {screenWidth/5.14573, screenHeight/1.08475}, --Pierwszy Tekst z informacjami(x,y)
[4] = {(screenHeight/1.035)}, --Glowny Tekst z informacjami(y)
[5] = {screenWidth/2.8, screenHeight/1.13}, --Drugi Tekst z informacjami(x,y)
[6] = {screenWidth/4.75, screenHeight/1.133,screenWidth/7.211, screenHeight/38.4,screenHeight/192,screenHeight/64}, --Obrazek HP itd(x,y)
[7] = {screenWidth/3.8, screenHeight/1.132}, --Tekst HP itd(x,y)
[8] = {screenWidth/1.1668185961713764813126709206928, screenHeight/12}, --Kills
[9] = {screenWidth/1.1668185961713764813126709206928, screenHeight/8.8888888888888888888888888888889}, --Deaths
[10] = {screenWidth/1.1668185961713764813126709206928, screenHeight/7.0588235294117647058823529411765}, --Ratio
[11] = {screenWidth/1.27205, screenHeight/5.6889,screenWidth/5.85142858, screenHeight/38.4}, --pasek HP
[12] = {screenWidth/1.1907, screenHeight/5.60584}, --pasek HP Text
[13] = {screenWidth/1.1700182815356489945155393053016, screenHeight/18.461538461538461538461538461538}, --Team
}

Ds1,Ds2 = getSizeFromResolution(screenWidth)
Us1,Us2 = getSizeFromResolution2(screenWidth)


local mnoznik = screenWidth/100
mnoznik = math.round(mnoznik, 0)
size1 = math.round(0.15*mnoznik, 1)
if size1 < 1 then
size1 = 1
end 

local size1a = math.round(0.04*mnoznik, 1)
if size1a >0.4 then size1a = 0.4 end
size1a = size1+size1a


local asd1 = 100
local rot  = 0
local rot2 = 0.5

local a = {}
local b = {}
for i=1,5 do
a[i] = 0
b[i] = 0
end

function onClientPlayerSpawn_bmc ( )
	local r1,g1,b1 = getTeamColor ( _t_i[1] )
	colors_t.team1 = tocolor(r1,g1,b1,255)
	local r2,g2,b2 = getTeamColor ( _t_i[2] )
	colors_t.team2 = tocolor(r2,g2,b2,255)
	t_c[_t_i[1]]=getTeamName(_t_i[1])
	t_c[_t_i[2]]=getTeamName(_t_i[2])
	P_t_info.Team = tostring(getTeamName(getPlayerTeam(getLocalPlayer())))
end
addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), onClientPlayerSpawn_bmc )


	local d_info_ = {tc_3=getTickCount(),r_m = '',sizet=math.min(yhy2(900,0.75),0.75),sizet2=math.round(math.min(yhy2(900,1.3),1.3),1),pos={getScreenPositionByRelative(0.23,0.8)},t_i={getScreenPositionByRelative(0.23,0.795)},t_t={getScreenPositionByRelative(0.24,0.83)},size={getScreenPositionByRelative(0.62,0.125)}}
	
	local wait_s = math.min(yhy2(900,0.6),0.6)
	function bm_onClientPreRender_WaitText()
	local nx1 = (screenWidth - asd1)/2 
	local r1,g1,b1 = getTeamColor ( _t_i[1] )
	local r2,g2,b2 = getTeamColor ( _t_i[2] )
	dxDrawImage ( 0,HudVars[1][1], screenWidth, HudVars[1][2],"img/px.png", 0, 0, 0, tocolor ( 255, 255, 255, 155 ))
	asd1 = dxDrawColorText(nx1, HudVars[4][1],wait_s, "bankgothic",1,colors_t.black,false,getTeamName(_t_i[1]).."(".._t_i[_t_i[1]].."): ","Players:  ",tostring(countPlayersInTeam ( _t_i[1] )),"    A/D Aspect RELOADED 1.0.6 by Mate_   ",getTeamName(_t_i[2]).."(".._t_i[_t_i[2]].."):  ","Players:  ",tostring(countPlayersInTeam ( _t_i[2] )),tocolor(r1,g1,b1,255),colors_t.gold,colors_t.gray,colors_t.green,tocolor(r2,g2,b2,255),colors_t.gold,colors_t.gray)
	end
	--addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_DrawGlobalText)


	

	
	
	
	local Table_i = {}
	function CreateSelectorButton()
		SpectGui_t.ftext = guiCreateLabel ( 0.0, 0.915, 1, 1, "Press F to show/hide cursor.",  true)
		guiSetFont ( SpectGui_t.ftext, "default-bold-small" )
		guiSetPosition(SpectGui_t.ftext,(1-getRelativeByScreenPosition((guiLabelGetTextExtent ( SpectGui_t.ftext )),0))/2,0.915,true)
		SpectGui_t.button1 = guiCreateButton ( 0.15, 0.91, 0.25, 0.035, "Select Team", true)
		guiSetAlpha(SpectGui_t.button1,0.75)
		Table_i[1] = guiCreateStaticImage ( 0.9,0.0, 0.1, 1.0, "img/dropdown.png", true,SpectGui_t.button1)
		ElementData[Table_i[1]] = "img1"
		addEventHandler ( "onClientGUIClick", Table_i[1], OnPlayerWantSelectOnNewMenu, false )
		SpectGui_t.button2 = guiCreateButton ( 0.6,0.91,0.25,0.035,"Camera Type", true)
		Table_i[2] = guiCreateStaticImage ( 0.9,0.0, 0.1, 1.0, "img/dropdown.png", true,SpectGui_t.button2)
		guiSetAlpha(SpectGui_t.button2,0.75)
		ElementData[Table_i[2]] = "img2"
		addEventHandler ( "onClientGUIClick", Table_i[2], OnPlayerWantSelectOnNewMenu, false )
	end

	function DestroySelectorButton()

	for k,v in ipairs(Table_i) do
	removeEventHandler ( "onClientGUIClick", v, OnPlayerWantSelectOnNewMenu, false )
	end
		for i=1,2 do 
			removeEventHandler ( "onClientGUIClick", SpectGui_t["Grid"..i], OnElementSelect, false )
			destroyElement(SpectGui_t["Grid"..i])
			removeEventHandler ( "onClientGUIClick", Table_i[i], OnPlayerWantSelectOnNewMenu, false )
			destroyElement(SpectGui_t["button"..i])
		end
		destroyElement(SpectGui_t.ftext)
		SpectGui_t = nil SpectGui_t ={}
		Table_i = nil Table_i ={}
	end



	local She_L = {
	Team={getScreenPositionByRelative(0.855,(0.0703-0.0143))},
	Kills={getScreenPositionByRelative(0.855,(0.1003-0.0143))},
	Deaths={getScreenPositionByRelative(0.855,(0.1303-0.0143))},
	Team2={getScreenPositionByRelative(0.903,(0.0703-0.0143))},
	Kills2={getScreenPositionByRelative(0.8983,(0.1003-0.0143))},
	Deaths2={getScreenPositionByRelative(0.915,(0.1303-0.0143))},
	hp={getScreenPositionByRelative(0.8775,(0.16145-0.012))},
	size1=yhy2(768,1.2),
	size2=yhy2(768,0.5),
	size3=yhy2(768,0.55),
	fps={getScreenPositionByRelative(0.98,0.005)},
	fps2={getScreenPositionByRelative(0.98,0.005)},
	}
	She_L.fps2 = {She_L.fps2[1]+1,She_L.fps2[2]+1}
	She_L.Team2[1] = She_L.Team[1] + dxGetTextWidth ( "Team: ", She_L.size3, "bankgothic" )
	She_L.Kills2[1] = She_L.Kills[1] + dxGetTextWidth ( "Kills: ", She_L.size3, "bankgothic" )
	She_L.Deaths2[1] = She_L.Deaths[1] + dxGetTextWidth ( "Deaths: ", She_L.size3, "bankgothic" )
	 
	 
	function bm_onClientPreRender_4()
	
		dxDrawText ("Team:", She_L.Team[1],She_L.Team[2] , 0, 0,colors_t.gold,She_L.size3, "bankgothic") 
		dxDrawText (P_t_info.Team, She_L.Team2[1],She_L.Team2[2] , 0, 0,colors_t.gray,She_L.size3 , "bankgothic") 

		dxDrawText ("Kills:", She_L.Kills[1],She_L.Kills[2] , 0, 0,colors_t.gold,She_L.size3 , "bankgothic") 
		dxDrawText (P_t_info.Kills, She_L.Kills2[1],She_L.Kills2[2] , 0, 0,colors_t.gray,She_L.size3 , "bankgothic") 

		dxDrawText ("Deaths:", She_L.Deaths[1],She_L.Deaths[2] , 0, 0,colors_t.gold,She_L.size2 , "bankgothic") 
		dxDrawText (P_t_info.Deaths, She_L.Deaths2[1],She_L.Deaths2[2] , 0, 0,colors_t.gray,She_L.size3 , "bankgothic") 

		dxDrawText (P_t_info.Health, She_L.hp[1],She_L.hp[2] , 0, 0,colors_t.gray,She_L.size2 , "bankgothic")
		local f = tostring(FPSLast)
		dxDrawText (f, She_L.fps2[1],She_L.fps2[2] , 0, 0,colors_t.black,1 ,"default-bold") 
		dxDrawText (f, She_L.fps[1],She_L.fps[2] , 0, 0,colors_t.lgreen,1 , "default-bold") 
	end

function OnClientDead_bm()
	if getElementData ( getLocalPlayer(),"IsSpawned" ) == 1 then
		setTimer(function()
			if getElementData ( sett,"Checking" ) == 0 then
				local sts = getElementData ( sett,"Round" )
				if sts == 1 or sts == 2 then 
					if getElementData ( getLocalPlayer(),"SpectStatus" ) == 0 then
						SetPlayerSpectateEnable()
						_game_status = 0
					end	
				end
			end	
		end,3500,1)
		
	end		
end
addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), OnClientDead_bm )

spec_t = {
size= yhy2(768,2.5),
size_2= math.max(yhy2(800,1.2),1),
pos={getScreenPositionByRelative(0.5,0.039)},
pos_b={getScreenPositionByRelative(0.2,0)},
size_b={getScreenPositionByRelative(0.8,0.125)},
line_s={getScreenPositionByRelative(0.01,0.105)},
line_p={getScreenPositionByRelative(0.8,0.01)},
team = {getScreenPositionByRelative(0.82,0.016)},
camera = {getScreenPositionByRelative(0.82,0.0485)},
health = {getScreenPositionByRelative(0.82,0.081)},
color_b=tocolor(0,0,0,178),
color_g=tocolor(238,180,34,178),
name="",
team_n="",
b_color=tocolor(238,180,34,255),
}


function dmg_c ()
	cancelEvent()
end

function SetPlayerSpectateEnable()
syncInterior (LocalPlayer,getElementData(sett,"m_interior"))
dxDrawTextAlongTime(6*40,screenWidth/2.8, screenHeight/1.2,yhy2(800,1.3),"sans","Use ",colors_t.gray,"<  >",colors_t.gold," or ",colors_t.gray,"R",colors_t.gold," to fast change spectate players.",colors_t.gray)
					addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), dmg_c)
					setElementData ( getLocalPlayer(),"SpectStatus",1 )
					ActualySpectMode.camera = "Normal"
					if getPlayerTeam(getLocalPlayer()) == TableTeams[3] then
					ActualySpectMode.team = "All teams"
					else
					ActualySpectMode.team = getTeamName(getPlayerTeam(getLocalPlayer()))
					end
					UpdateSpectTable(ActualySpectMode.team)
					actualyspectInt = 1
				--	showPlayerHudComponent ( "radar", false )
				--	setCameraTarget(spect_t[1])
					ActuallySpec = spect_t[1]
					setCameraTarget(ActuallySpec)
					spec_t.name = tostring(getPlayerName(ActuallySpec))
					spec_t.team_n = tostring(getTeamName(getPlayerTeam(ActuallySpec)))
					spec_t.pos[1] = (screenWidth - dxGetTextWidth ( spec_t.name, spec_t.size,"default-bold" ))/2
					removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4) 
					removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
					addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_3)
					CreateSelectorButton( )
				--[[	bindKey ( "f", "down", ShowHideCursor )
					bindKey ( "r", "down", FastChangeSpectate )
					bindKey ( "arrow_l", "down", ChangeSpectate )
					bindKey ( "arrow_r", "down", ChangeSpectate )]]
					bindKey ( "f", "down",ShowHideCursor )
					bindKey ( "r", "down",PreFastChangeSpectate)
					bindKey ( "arrow_l", "down",PreChangeSpectate)
					bindKey ( "arrow_r", "down",PreChangeSpectate )
					setElementFrozen ( localPlayer,true )
					triggerEvent ( "AddSpectateMode", getRootElement() )
					addEventHandler("onClientRender", getRootElement(),draw_SpectTarget)
					addEventHandler("onClientPlayerWeaponFire", getRootElement(), onClientPlayerWeaponFireFunc_spect)
					fadeCamera(true,0)

end



	function UpdateSpectTable(type_)
	local TeamP 
	if table.getn(spect_t) > 0 then
	spect_t = nil
	spect_t = { }
	end
		if type_ == "All teams" then	
			TeamP = getElementsByType("player")
		elseif getTeamFromName(type_) ~= false then
			TeamP = getPlayersInTeam (getTeamFromName(type_))
		end
			if TeamP then
				for k,v in ipairs(TeamP) do
					if v ~= getLocalPlayer() and getElementData ( v,"IsSpawned" ) == 1 then
					table.insert( spect_t, v )
					end	
				end
			end
	end
	


	function GetPlayerNamesFromTableSpectators()
	local new_t = {}
		for k,v in ipairs(spect_t) do
		table.insert( new_t, tostring(getPlayerName(v)) )
		end
	return new_t
	end
	

	addEventHandler ( "onClientElementDataChange", getRootElement(),
function ( dataName )
if dataName == "Capturing" then
	if getElementData ( sett,"Capturing" ) == 0 then
	 addEventHandler("onClientRender", getRootElement(), DrawCapturingSts)
	elseif getElementData ( sett,"Capturing" ) == -1 then
	 removeEventHandler("onClientRender", getRootElement(), DrawCapturingSts)
	end
end	

if getElementData ( getLocalPlayer(),"SpectStatus" ) == 1 then
if dataName == "Active_Players" then
	if getElementType ( source ) == "team" then
	UpdateSpectTable(ActualySpectMode.team)	
	end
end	
if dataName == "Round" and getElementData ( source,"Round" ) == 0  then
	--[[if getElementData ( getLocalPlayer(),"SpectStatus" ) == 1 then
		RemoveSpectateMode()
	end]]
end
	if dataName == "IsSpawned" and getElementData ( source,"IsSpawned" ) == 0  then
	DeleteeAntiRushZone()
	removeEventHandler("onClientRender", getRootElement(), ehehe)
		if isTimer(spawn_t) then
			RemoveSpawnProt()
		end	
		
	end

end
end )
local KeySts = false
function ShowHideCursor()
	if KeySts == false then
	showCursor(true)
	KeySts = true
	else
	showCursor(false)
	KeySts = false
	end
end



function RemoveSpectateMode(fix)
	if getElementData ( getLocalPlayer(),"SpectStatus") ~= 0 then
		removeEventHandler ( "onClientPlayerDamage", getLocalPlayer(), dmg_c)
		removeEventHandler("onClientRender", getRootElement(),draw_SpectTarget)
		removeEventHandler("onClientPlayerWeaponFire", getRootElement(), onClientPlayerWeaponFireFunc_spect)
		showCursor(false)
		KeySts = false
		--[[unbindKey ( "f", "down", ShowHideCursor )
		unbindKey ( "r", "down", FastChangeSpectate )
		unbindKey ( "arrow_l", "down", ChangeSpectate )
		unbindKey ( "arrow_r", "down", ChangeSpectate )]]
			unbindKey ( "f", "down",ShowHideCursor )
			unbindKey ( "r", "down",PreFastChangeSpectate )
			unbindKey ( "arrow_l", "down",PreChangeSpectate )
			unbindKey ( "arrow_r", "down",PreChangeSpectate )
		showPlayerHudComponent ( "radar", true )
		setElementData ( getLocalPlayer(),"SpectStatus",0 )
		removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_3) 
		addEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_4) 
		DestroySelectorButton()
		call(getResourceFromName("freecam"), "setFreecamDisabled")
		if fix == nil then
		setCameraTarget(getLocalPlayer())
		end
				if draw_t.size ~= 8 then
					removeEventHandler("onClientRender", getRootElement(),renderanim)
				end
	end
end
function PreFastChangeSpectate()
	--LoadingAnimation(500,'FastChangeSpectate')
	FastChangeSpectate()
	sdasddsadsa(500)
end
function PreChangeSpectate()
	--LoadingAnimation(500, 'ChangeSpectate' )
	ChangeSpectate()
	sdasddsadsa(500)
end
function FastChangeSpectate()
		if actualyspectInt >= table.getn(spect_t) then
		actualyspectInt = 1
		else
		actualyspectInt =actualyspectInt +1
		end
	local MyMay = setCameraTarget(spect_t[actualyspectInt])
	if MyMay == true then
	ActuallySpec = spect_t[actualyspectInt]
	spec_t.name = getPlayerName(ActuallySpec)
	spec_t.team_n = getTeamName(getPlayerTeam(ActuallySpec))
	spec_t.pos[1] = (screenWidth - dxGetTextWidth ( spec_t.name, spec_t.size,"default-bold" ))/2
	end	
end


function ChangeSpectate(key)
	if key == "arrow_r" then
		if actualyspectInt >= table.getn(spect_t) then
		actualyspectInt = 1
		else
		actualyspectInt =actualyspectInt +1
		end
	else
		if actualyspectInt <= 1 then
		actualyspectInt = table.getn(spect_t)
		else
		actualyspectInt =actualyspectInt -1
		end
	end
	
	local MyMay = setCameraTarget(spect_t[actualyspectInt])
	if MyMay == true then
	ActuallySpec = spect_t[actualyspectInt]
	spec_t.name = getPlayerName(ActuallySpec)
	spec_t.team_n = getTeamName(getPlayerTeam(ActuallySpec))
	spec_t.pos[1] = (screenWidth - dxGetTextWidth ( spec_t.name, spec_t.size,"default-bold" ))/2
	end
end

	local cpt_t = {x=math.min(2,screenWidth/640)}
		cpt_t.bg_size = {200*cpt_t.x,50*cpt_t.x,7.5*cpt_t.x,24.5*cpt_t.x,0.5*cpt_t.x,10*cpt_t.x}
			cpt_t.bg_size[5] = cpt_t.bg_size[5]*3.7
				cpt_t.bg_realtive = {getRelativeByScreenPosition(cpt_t.bg_size[1] ,cpt_t.bg_size[2])}
			cpt_t.bg_pos = {getScreenPositionByRelative( (1-cpt_t.bg_realtive[1])/2,0.86)}
		cpt_t.i_pos = { cpt_t.bg_pos[1]+cpt_t.bg_size[3],cpt_t.bg_pos[2]+cpt_t.bg_size[4]}
	cpt_t.text_pos = {cpt_t.i_pos[1] + (cpt_t.bg_size[5]*45),cpt_t.i_pos[2]}
	--cpt_t.text_pos = {getScreenPositionByRelative( 0.45,0.9)}
function DrawCapturingSts()
	dxDrawImage ( cpt_t.bg_pos[1], cpt_t.bg_pos[2],cpt_t.bg_size[1],  cpt_t.bg_size[2], "img/cp_bg.png")
		dxDrawImage ( cpt_t.i_pos[1], cpt_t.i_pos[2],cpt_t.bg_size[5]*getElementData ( sett,"Capturing" ),  cpt_t.bg_size[6], "img/cp_1px.png")
	dxDrawText (tostring(getElementData ( sett,"Capturing" )).."%", cpt_t.text_pos[1],cpt_t.text_pos[2] , 0, 0,colors_t.gray,She_L.size1 , "default") 
end

-- Update_Tsts
addEventHandler ( "onClientElementDataChange", getRootElement(),
function ( dataName )
	if getElementType ( source ) == "team" and dataName == "t_type" then
		_t_i[1] = getTeamByType("Attack")
		_t_i[2] = getTeamByType("Defense")
		_t_i[_t_i[1]] = "Att"
		_t_i[_t_i[2]] = "Def"
	local r2,g2,b2 = getTeamColor ( _t_i[2] )
	colors_t.team2 = tocolor(r2,g2,b2,255)
	local r1a,g1a,b1a = getTeamColor ( _t_i[1] )
	colors_t.team1 = tocolor(r1a,g1a,b1a,255)
	end
end )

function DxDrawWin(times,x,y,scale,font,outlinesize,team)
local r,g,b = getTeamColor(team)
local nme = getTeamName(team)
DxDrawTimeText(times,screenWidth/x,screenHeight/y,math.round(size1*scale, 2),font,math.round(size1*outlinesize, 2), colors_t.black,false,tostring(nme)," win!",tocolor(r,g,b,255),colors_t.gold)
end

function DxDrawDraw(times,x,y,scale,font,outlinesize,team)
local r,g,b = 0,128,128
local nme = team
DxDrawTimeText(times,screenWidth/x,screenHeight/y,math.round(size1*scale, 2),font,math.round(size1*outlinesize, 2), colors_t.black,false,tostring(nme),tocolor(r,g,b,255))
end

function DxDrawDrawClientText(times,x,y,scale,font,outlinesize,team,r,g,b)
local nme = team
DxDrawTimeText(times,screenWidth/x,screenHeight/y,math.round(size1*scale, 2),font,math.round(size1*outlinesize, 2), colors_t.black,false,tostring(nme),tocolor(r,g,b,255))
end



--// kicker systen new



function _core_avg(t,f)
	if #t < 4 then
		return false
	end	
local sum = 0
	for k,v in ipairs(t) do
		sum = sum + v
	end
	return math.round(sum/#t,f)
end

function _core_kick_system()
	if  _game_status == 1 then
		table.insert(k_system.fps, FPSLast)
		if isTransferBoxActive () == false  then
			table.insert(k_system.ping, getPlayerPing(localPlayer))
			k_system.packet[1] = k_system.packet[1] + getNetworkStats ( ).packetlossLastSecond
			k_system.packet[2] = k_system.packet[2] + 1
		end
		
		-- packet loss
		
						
		if k_system.packet[2] > 59 then
			local res = math.round(k_system.packet[1]/k_system.packet[2],2)
			if res > game_settings.kickere[3] then
			--	callServer("outputChatBox",getPlayerName(localPlayer).. " : High packet loss "..tostring(res).." (  max  allowed: "..tostring(math.round(game_settings.kickere[3],2)).." )",getRootElement())
			--	callServer("outputServerLog",getPlayerName(localPlayer).. " : High packet loss "..tostring(res).." (  max  allowed: "..tostring(math.round(game_settings.kickere[3],2)).." )")
			callServer("kickPlayer",localPlayer, getRootElement(),"High packet loss "..tostring(res).." (  max  allowed: "..tostring(math.round(game_settings.kickere[3],2)).." )")
			end
			k_system.packet={res,1}
		end
		
		if getTickCount()- k_system.tc > 30000 then
			k_system.tc = getTickCount()
			for k,v in ipairs({{'ping',0,2,'High ping ',' max'},{'fps',0,1,'Low FPS ',' min'}}) do
				local res = _core_avg(k_system[v[1]],v[2])
			--	outputChatBox(v[1].." : ".. game_settings.kickere[v[3]]) 
					if k == 3 then
	
					elseif k == 2 then
						if res ~= false and res < game_settings.kickere[v[3]] then
							callServer("kickPlayer",localPlayer, getRootElement(),v[4]..tostring(res).." ( "..v[5]..v[5].." ( allowed: "..tostring(math.round(game_settings.kickere[v[3]],v[2])).." )")
						end
					else
						if res ~= false and res > game_settings.kickere[v[3]] then
							callServer("kickPlayer",localPlayer, getRootElement(),v[4]..tostring(res).." ( "..v[5]..v[5].." ( allowed: "..tostring(math.round(game_settings.kickere[v[3]],v[2])).." )")
						end
					end	
			end
			k_system.ping = {} k_system.ploss = {} k_system.fps = {} 
		end
	end
end
setTimer( function() 
	setTimer(_core_kick_system,1000,0)
end,10000,1)	


---////////////////////////////////////////////






local dx_hud = {t1name="",title="",colors={colors_g.gray,colors_g.gray}}
addEvent ( "createHudManufacture", true )
local hud_texts = {size=math.min(yhy2(900,0.75),0.75),size2=math.min(yhy2(900,0.85),0.85)}
function dxDrawH()
dxDrawImage (hud_texts.leftC[1], hud_texts.leftC[2], hud_texts.leftC[3], hud_texts.leftC[4], "img/hud/leftC.png" ,0, 0,  0, dx_hud.colors[1], true )
dxDrawImage (hud_texts.rightC[1], hud_texts.rightC[2], hud_texts.rightC[3], hud_texts.rightC[4], "img/hud/rightC.png" ,0, 0,  0, dx_hud.colors[2], true )
dxDrawText ( dx_hud.t1, hud_texts.t1[1],hud_texts.t1[2] , 0, 0,colors_g.gray,hud_texts.size2l , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( dx_hud.t2, hud_texts.t2[1],hud_texts.t2[2] , 0, 0,colors_g.gray,hud_texts.size2r , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( dx_hud.title, hud_texts.title[1],hud_texts.title[2] , 0, 0,colors_g.gray,hud_texts.size , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( T_table_info[_t_i[1]].Score, hud_texts.scorel[1],hud_texts.scorel[2] , 0, 0,colors_g.gray,hud_texts.size , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( T_table_info[_t_i[2]].Score, hud_texts.scorer[1],hud_texts.scorer[2] , 0, 0,colors_g.gray,hud_texts.size , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( T_table_info[_t_i[1]].Active_Players, hud_texts.playersl[1],hud_texts.playersl[2] , 0, 0,colors_g.gray,hud_texts.size , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( T_table_info[_t_i[1]].Health, hud_texts.hearhl[1],hud_texts.hearhl[2] , 0, 0,colors_g.gray,hud_texts.size , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( T_table_info[_t_i[2]].Active_Players, hud_texts.playersr[1],hud_texts.playersr[2] , 0, 0,colors_g.gray,hud_texts.size , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( T_table_info[_t_i[2]].Health, hud_texts.hearhr[1],hud_texts.hearhr[2] , 0, 0,colors_g.gray,hud_texts.size , "bankgothic", "left", "top",false, false, true) 
dxDrawText ( G_hud, hud_texts.time[1],hud_texts.time[2], 0, 0,colors_g.gray,hud_texts.size , "bankgothic", "left", "top",false, false, true) 
end
--

--[[function returnFontSize(t)
	local l = string.len(t)
	outputChatBox('CHUJU '..tostring( yhy2(0.75,900) - ((l-5)*0.15)))
	outputChatBox('CHUJU2 '..tostring( math.max(math.min(0.75 - ((l-5)*yhy2(0.15,900)),0.75),0.4)))
	return math.max(math.min(yhy2(0.75,900) - ((l-5)*0.15),0.75),0.4)
end]]

function returnFontSize(t)
	local l = string.len(t)
	local l_w = hud_texts.leftC[3]/l
	return petla(l_w,l)
end


function petla(w,l)
local t_r = {}
	for i=0,1,0.025 do
		local a = dxGetTextWidth ( 'A', i, "bankgothic" )
			if a+0.5 > w and a < w +0.5 then
				return i
			end
	end
	return 0.75
end

function createHudManufacture(t1,t2)

if dx_hud.gui1 == nil then
local height =  {math.min(yhy2(900,35),35),screenHeight- math.min(yhy2(900,35),35)}
local space=math.min(yhy2(900,38),38)
local asd = {t2=(screenWidth-math.min(yhy2(900,100),100)),t1=getScreenPositionByRelative(0.005,0),title= getScreenPositionByRelative(0.385,0),hearhl =  getScreenPositionByRelative(0.111,0),playersl =  getScreenPositionByRelative(0.210,0),scorel =  getScreenPositionByRelative(0.305,0)
,hearhr =  getScreenPositionByRelative(0.535+0.111,0),playersr =  getScreenPositionByRelative(0.535+0.210,0),scorer =  getScreenPositionByRelative(0.535+0.305,0),time =  getScreenPositionByRelative(0.51,0)}
	for k,v in pairs(asd) do
		hud_texts[k]={v+space,height[2] +2+((height[1]-dxGetFontHeight ( hud_texts.size, "bankgothic" ))/2)}
	end
--	hud_texts.size2 = dxGetTextWidth (dx_hud.t1, [float scale=1, string font="default"] )
	dx_hud.t1 = tostring( getTeamName(t1))
	dx_hud.t2 = tostring( getTeamName(t2))

	dx_hud.colors = {}
	local r,g,b = getTeamColor(t1)
	dx_hud.colors[1] = tocolor(r,g,b,255)
	r,g,b = getTeamColor(t2)
	dx_hud.colors[2] = tocolor(r,g,b,255)	
	--hud_texts.size2l = math.min(yhy2(900,string.len(dx_hud.t1)*0.15),string.len(dx_hud.t1)*0.15)

		
	dx_hud.title = tostring(string.gsub(P_t_info.RoundName, "arena", "Arena")or string.gsub(P_t_info.RoundName, "base", "Base")).." "..P_t_info.RoundInt
dx_hud.gui1 = guiCreateStaticImage ( 0,  height[2], math.min(yhy2(900,100),100), height[1],"img/hud/left.png",false)
hud_texts.leftC = {0,  height[2], math.min(yhy2(900,100),100), height[1]}
local backg2 = math.min(yhy2(900,284),284)
dx_hud.gui2 = guiCreateStaticImage ( math.min(yhy2(900,100),100),  height[2], (screenWidth-math.min(yhy2(900,100),100))-((screenWidth-backg2)/2 + backg2), height[1],"img/hud/backg.png",false)
dx_hud.gui12 = guiCreateStaticImage (((screenWidth-backg2)/2 + backg2),  height[2], (screenWidth-math.min(yhy2(900,100),100))-((screenWidth-backg2)/2 + backg2), height[1],"img/hud/backg.png",false)
dx_hud.gui3 = guiCreateStaticImage ( ((screenWidth-backg2)/2),  height[2], backg2, height[1],"img/hud/backg2.png",false)

dx_hud.gui4 = guiCreateStaticImage ( screenWidth-math.min(yhy2(900,100),100), height[2], math.min(yhy2(900,100),100), height[1],"img/hud/right.png",false)
hud_texts.rightC = {screenWidth-math.min(yhy2(900,100),100), height[2], math.min(yhy2(900,100),100), height[1]}
dx_hud.gui5 = guiCreateStaticImage ( asd.hearhl, height[2]+4, math.min(yhy2(900,33),33), math.min(yhy2(900,30),30),"img/hud/hearh.png",false)
dx_hud.gui6 = guiCreateStaticImage ( asd.scorel, height[2]+4, math.min(yhy2(900,30),30), math.min(yhy2(900,30),30),"img/hud/score.png",false)
dx_hud.gui7 = guiCreateStaticImage ( asd.playersl, height[2]+4, math.min(yhy2(900,30),30), math.min(yhy2(900,30),30),"img/hud/players.png",false)
dx_hud.gui8 = guiCreateStaticImage ( asd.hearhr, height[2]+4, math.min(yhy2(900,33),33), math.min(yhy2(900,30),30),"img/hud/hearh.png",false)
dx_hud.gui9 = guiCreateStaticImage ( asd.scorer, height[2]+4, math.min(yhy2(900,30),30), math.min(yhy2(900,30),30),"img/hud/score.png",false)
dx_hud.gui10 = guiCreateStaticImage ( asd.playersr, height[2]+4, math.min(yhy2(900,30),30), math.min(yhy2(900,30),30),"img/hud/players.png",false)
dx_hud.gui11 = guiCreateStaticImage ( asd.time, height[2]+4, math.min(yhy2(900,30),30), math.min(yhy2(900,30),30),"img/hud/time.png",false)

	hud_texts.size2l = returnFontSize(dx_hud.t1)
	hud_texts.size2r = returnFontSize(dx_hud.t2)
	hud_texts.t1 = {hud_texts.t1[1]-space,height[2] +2+((height[1]-dxGetFontHeight (hud_texts.size2l, "bankgothic" ))/2)}
	hud_texts.t2 = {hud_texts.t2[1]-space,height[2] +2+((height[1]-dxGetFontHeight (hud_texts.size2r, "bankgothic" ))/2)}
--outputChatBox('per '..tostring( client_settings[4] ))
local percent = tonumber ( string.sub ( client_settings[4],1,string.len( client_settings[4] )-1 ) )/100
--outputChatBox('per2 '..tostring( percent ))
--outputChatBox('per3 '..tostring( math.min(1- percent, percent)  ))

guiSetAlpha ( dx_hud.gui2, percent )
guiSetAlpha ( dx_hud.gui12, percent )
guiSetAlpha ( dx_hud.gui3, percent )
guiSetAlpha ( dx_hud.gui4, percent)
guiSetAlpha ( dx_hud.gui1, percent )
addEventHandler("onClientRender", getRootElement(),dxDrawH)
removeEventHandler("onClientRender", getRootElement(), bm_onClientPreRender_WaitText)
--outputChatBox('LEFTC: '..tostring( hud_texts.leftC[3]))
end
end
addEventHandler (  "createHudManufacture", getLocalPlayer(), createHudManufacture )

function destroyHudManufacture()
for i=1,12 do
	if isElement(dx_hud["gui"..tostring(i)]) then
		destroyElement(dx_hud["gui"..tostring(i)])
	end
end
removeEventHandler("onClientRender", getRootElement(),dxDrawH)
dx_hud = {t1name="",title="",colors={colors_g.gray,colors_g.gray}}
removeEventHandler("onClientRender", getRootElement(), ehehe)
end




function draw_SpectTarget()
	if ActuallySpec and getPedControlState ( ActuallySpec, "aim_weapon" ) then
	local hitX, hitY, hitZ =   getPedTargetCollision (  ActuallySpec )
			if not hitX then
				hitX, hitY, hitZ =   getPedTargetEnd ( ActuallySpec )
			end
		if hitX then
		local x,y = getScreenFromWorldPosition (hitX, hitY, hitZ, 0, false)
			if x then 
				dxDrawLine ( x-draw_t.size, y, x+draw_t.size, y,draw_t.color )
				dxDrawLine ( x, y-draw_t.size, x, y+draw_t.size,draw_t.color )
			end
		end
	end	
end


local wwwww ={[22]=18,[23]=20,[24]=26,[25]=24,[25]=28,[27]=22,[30]=20,[31]=16,[33]=14,[34]=14,[38]=12}
function onClientPlayerWeaponFireFunc_spect(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement)
	if source == ActuallySpec then
		draw_t.max =  wwwww[weapon] or 20
		if draw_t.size == 8 then
		addEventHandler("onClientRender", getRootElement(),renderanim)
		end
	end
end


function renderanim()
draw_t.size=draw_t.size+draw_t.mn
	if draw_t.size == draw_t.max then
	draw_t.mn = -2
	elseif draw_t.size == 8 then
		removeEventHandler("onClientRender", getRootElement(),renderanim)
		draw_t.mn = 2
	end
end




function bm_onClientPreRender_3()
	if ActuallySpec then
		dxDrawImage (spec_t.pos_b[1],spec_t.pos_b[2], spec_t.size_b[1],spec_t.size_b[2],"img/spect.png", 0, 0, 0, spec_t.color_b)
			dxDrawImage (spec_t.line_p[1],spec_t.line_p[2],1,spec_t.line_s[2],"img/gui_bar1.png", 0, 0, 0, spec_t.color_g)
				dxDrawText ( spec_t.name, spec_t.pos[1],spec_t.pos[2] , 0, 0,spec_t.b_color,spec_t.size , "default-bold") 
				dxDrawTexts(spec_t.team[1],spec_t.team[2],spec_t.size_2,"default-bold","Team:  ",spec_t.b_color,spec_t.team_n,colors_t.gray)
			dxDrawTexts(spec_t.camera[1],spec_t.camera[2],spec_t.size_2,"default-bold", "Kills:  ",spec_t.b_color,tostring(getElementData ( ActuallySpec,"Kills")),colors_t.gray, "  Deaths:  ",spec_t.b_color,tostring(getElementData ( ActuallySpec,"Deaths")),colors_t.gray)
		dxDrawTexts(spec_t.health[1],spec_t.health[2],spec_t.size_2,"default-bold","Health:  ",spec_t.b_color,string.format("%.0f",getElementHealth(ActuallySpec)),colors_t.gray)
	end
	end
	
	
	

	
	function onClientPlayerWasted_e ( killer, weapon, bodypart )
		if source ~= getLocalPlayer() and killer == getLocalPlayer() then
		--	local x,y,z = getElementPosition(source)
		--	createExplosion ( x,y,z , 12,false,0, false )
			for i=1,3 do
				playSoundFrontEnd ( 11)
			end
		end
		if getElementData ( getLocalPlayer(),"SpectStatus" ) == 1 and getElementData ( sett,"Round" ) ~= 0 and source == ActuallySpec then
			UpdateSpectTable(ActualySpectMode.team)	
			--LoadingAnimation( 500,'FastChangeSpectate')
			FastChangeSpectate()
			sdasddsadsa(500)
		end
	end	
	addEventHandler ( "onClientPlayerWasted", getRootElement(), onClientPlayerWasted_e )
	
	
	local lp = getLocalPlayer()
	local ehe_fps = 1
	local ehe_tc = getTickCount()
	ehe_p = 100
	function ehehe()
		ehe_fps = ehe_fps +1
		if ehe_fps == 30 then
			local hp = math.round(getElementHealth(lp), 0)
				if hp ~= ehe_p then
					setElementData ( lp, "Health", hp  )
					ehe_p = hp
				end
		ehe_fps = 1	
		end	
	end
	--addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), ehehe ) 
	--addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), ehehe ) 
	local  change_team_t = {}
	function change_team_window(boold)
		if not change_team_t.window and getElementData ( sett,"Round" ) == 0 then
			change_team_t.d = boold
			change_team_t.window = guiCreateWindow ((screenWidth-400)/2, (screenHeight-100)/2, 400, 100, "Select your team",false )
			change_team_t.t1 = guiCreateButton ( 0.05, 0.3, 0.266, 0.3, getTeamName(TableTeams[1]), true, change_team_t.window )
			change_team_t.t2 = guiCreateButton ( 0.366, 0.3, 0.266, 0.3, getTeamName(TableTeams[2]), true, change_team_t.window )
			change_team_t.t3 = guiCreateButton ( 0.672, 0.3, 0.266, 0.3, getTeamName(TableTeams[3]), true, change_team_t.window )
			change_team_t.close = guiCreateButton ( 0.05, 0.72, 0.9, 0.15, "close", true, change_team_t.window )
			addEventHandler ( "onClientGUIClick", change_team_t.t1, change_team_accept, false )
			addEventHandler ( "onClientGUIClick", change_team_t.t2, change_team_accept, false )
			addEventHandler ( "onClientGUIClick", change_team_t.t3, change_team_accept, false )
			addEventHandler ( "onClientGUIClick",change_team_t.close, change_team_accept, false )
			showCursor(true)
		end
	end
	
	function change_team_accept()
		if source == change_team_t.t1 then
			change_team_spawn(TableTeams[1])
		elseif source == change_team_t.t2 then
			change_team_spawn(TableTeams[2])
		elseif source == change_team_t.t3 then
			change_team_spawn(TableTeams[3])
		elseif source == change_team_t.close then
			destroyElement(change_team_t.window)
			change_team_t = {}
			showCursor(false)
		end
	end
	 
	 
	function change_team_spawn(team)
		if change_team_t.d and getElementType(change_team_t.d) == 'player' then
			callServer("ChangePlayerTeam", change_team_t.d,team)	
			movePanel()
		else
			callServer("ChangePlayerTeam", getLocalPlayer(),team)		
		end	
		destroyElement(change_team_t.window)
		change_team_t  = {}
		showCursor(false)
	end
	
	function formatHistory(history_data)
	if #history_data == 0 then
		return "There is no recently played rounds in the history."
	end	
	if round_mode[1] == 'normal' then	
		return "This feature works only in match mode, available as /startmatch [base/tdm] [rouds] command."
	end	
	local now = ""
		for k, v in ipairs(history_data) do
			if v[1] == "arena" then
				local a =  v[1].." "..v[2] .." | Winner: " .. tostring(v[5]).." | Players left: "..tostring( v[7]).." with "..tostring( v[8]).."hp"
				now = now..a.."\n\n"
			else
				local a =   v[1].." "..v[2] ..": Type: "..tostring( v[6]).." | Defend: "..tostring( v[4]).." | Winner: ".. tostring(v[5]).." | Players left: "..tostring( v[7]).." with "..tostring( v[8]).."hp"
				now = now..a.."\n\n"
			end	
		end
		return now
	end
	--13
	--17
	 help = {}
	function help_window(data,history_data,cmds_b)
		help.infoMemo = guiCreateMemo ( 0.00, 0.00, 1, 1,"\nServer version: "..data.ver[1].."\nServer os: "..data.ver[2].."\nServer type: "..data.ver[3].."\n\nFPS Limit: "..data.fps.."\nConfing: "..tostring(data.cfg).."\n\nList of running resources: \n"..data.admins, true, help.info )
		guiMemoSetReadOnly (help.infoMemo, true )
		help.historyMemo = guiCreateMemo ( 0.00, 0.00, 1, 1,"\n"..formatHistory(history_data), true, help.history  )
		guiMemoSetReadOnly (help.historyMemo, false)
		help.statsMemo = guiCreateMemo ( 0.00, 0.00, 1, 1,"\nYour current stats:\n\nScore: "..tostring(client_settings[13]).."\nKills: "..tostring(client_settings[14]).."\nDeaths: "..tostring(client_settings[15]).."\nDamage: "..tostring(client_settings[16]).."\nRatio: "..tostring(client_settings[14]/client_settings[15]), true, help.stats  )
		guiMemoSetReadOnly (help.statsMemo, false)
		local string_ = "\n"
		if #cmds_b > 0 then
			for k, v in ipairs(cmds_b) do
			local time_s = getRealTime( v[2] )
				string_ = string_.. ( "["..time_s.hour..":"..time_s.minute..":"..time_s.second.."]: "..v[3].." has used the command: /"..v[1]).."  \n"
			end
		else
			string_ = "There is no commands in the history."
		end
		help.cmdsMemo = guiCreateMemo ( 0.00, 0.00, 1, 1,string_, true, help.cmds  )
		guiMemoSetReadOnly (help.cmdsMemo, false)
		help.grid_settings = guiCreateGridList (  0.015, 0.025, 0.97, 0.95 ,true, help.settings )
		guiGridListSetSelectionMode (help.grid_settings, 0 )
        guiGridListAddColumn ( help.grid_settings , 'Settings', 0.5 )
        guiGridListAddColumn ( help.grid_settings , 'Value', 0.4 )
			--local settings_l ={{'Hit sound','false'},{"Qetting hit sound",'false'},{'Arena bound quality','low'},{'Hud transparency','0%'},{'',''},{'---Binds---------------------------------------------------',''},{'',''},{'Call Help','h'},{'Admin Panel','F1'},{'About Panel','F5'},{'Team selector','F4'}}
			local settings_l ={{'Hit sound',''},{"Qetting hit sound",''},{'Arena bound quality',''},{'Hud transparency',''},{'Damage effect',''},{'',''},{'---Binds---------------------------------------------------',''},{'',''},{'Call Help',''},{'Admin Panel',''},{'About Panel',''},{'Team selector',''},{'Reload Weapon',''}}
			for k,v in ipairs(settings_l) do
				local row = guiGridListAddRow (help.grid_settings )
				guiGridListSetItemText ( help.grid_settings, row, 1, v[1], false, false )
				guiGridListSetItemText ( help.grid_settings, row, 2, v[2], false, false )
			end
			for i=0,3 do
				guiGridListSetItemText ( help.grid_settings, i, 2, client_settings[i+1], false, false )
			end
			for i=8,11 do
				guiGridListSetItemText ( help.grid_settings, i, 2, client_settings[i-3], false, false )
			end
			guiGridListSetItemText ( help.grid_settings, 4, 2, client_settings[17], false, false )
			guiGridListSetItemText ( help.grid_settings, 12, 2, tostring(client_settings[18]), false, false )
		function accept() 
			if source == help.close then
				showCursor(false)
				removeEventHandler ( "onClientGUIClick",help.close, accept )	
				removeEventHandler ( "onClientClick",getRootElement() , bring )	
				removeEventHandler( "onClientGUIDoubleClick", help.grid_settings, help_window_click )	
				destroyElement(help.window )
				help = {}
				_client_panel_save()
				functionToBindOtherFunctions()
			end
		end
		function bring() 
			guiMoveToBack( help.tab )
		end
		addEventHandler ( "onClientGUIClick",help.close, accept, true )	
		addEventHandler ( "onClientClick",getRootElement() , bring, true )	
		addEventHandler( "onClientGUIDoubleClick", help.grid_settings, help_window_click )	
		showCursor(true)
	end
	
	function help_window_click()	
		local row, column = guiGridListGetSelectedItem ( source )
		if row ~= -1 and column then
			local data  = {guiGridListGetItemText ( source, row, column ),guiGridListGetItemText ( source, row, column+1 )}
			help.edit = {set={source,row, column+1,data[1]}}
				if data[1] == 'Hit sound' or data[1] == 'Qetting hit sound' or data[1] == 'Arena bound quality' or data[1] == 'Hud transparency' or data[1] == 'Damage effect' then
					local s_t = {['Hit sound']={'true','false'},['Qetting hit sound']={'true','false'},['Arena bound quality']={'low','medium','high'},['Damage effect']={'true','false'},['Hud transparency']={'0%','10%','20%','30%','40%','50%','60%','70%','80%','90%','100%'},}
						for i=1,#s_t[data[1]] do
							if data[2] == s_t[data[1]][i] then
								if i == #s_t[data[1]] then
									guiGridListSetItemText (help.edit.set[1],help.edit.set[2],help.edit.set[3],s_t[data[1]][1],false ,false)
								--	help_update_table( source,data[1],s_t[data[1]][1])
									help_onClientUpdate()
								else
									guiGridListSetItemText (help.edit.set[1],help.edit.set[2],help.edit.set[3],s_t[data[1]][i+1],false ,false)
								--	help_update_table( source,data[1],s_t[data[1]][i+1])
									help_onClientUpdate()
								end
									
								break
							end
						end
					return false
				else
					guiSetPosition ( help.window, 1, 1, true)
					help.infoa = guiCreateLabel ( 0.351, 0.491, 0.4, 0.1, 'Press a key to bind, or ENTER to cancel.',true )
					help.info = guiCreateLabel ( 0.35, 0.49, 0.4, 0.1, 'Press a key to bind, or ENTER to cancel.',true )
					guiSetFont ( help.info,myFont )
					guiSetFont ( help.infoa,myFont )
					guiLabelSetColor (help.infoa, 0, 0, 0 )
					addEventHandler("onClientKey", getRootElement(), help_onClientKey)
				end
		end		
	end
	
	function help_onClientUpdate()
	local j = 1 
				for i=0,11 do
					if i ~= 4 and i ~= 5 and i ~= 6 and i ~= 7 then
							client_settings[j] = guiGridListGetItemText (help.edit.set[1],i,help.edit.set[3])
							j=j+1
							
					end	
				end
				client_settings[17] = guiGridListGetItemText (help.edit.set[1],4,help.edit.set[3])
				client_settings[18] = guiGridListGetItemText (help.edit.set[1],12,help.edit.set[3])
	end
	function help_onClientKey(button, press)
		if (press) then 
			if button == 'enter' then
				removeEventHandler("onClientKey", getRootElement(), help_onClientKey)
				destroyElement( help.info)
				destroyElement( help.infoa)
				guiSetPosition ( help.window, (screenWidth-550)/2, (screenHeight-350)/2,false)	
			elseif string.find(button,'mouse') == nil then
				for i=7,10 do
					if guiGridListGetItemText (help.edit.set[1],i,help.edit.set[3]) == button then
						guiGridListSetItemText (help.edit.set[1],i,help.edit.set[3],'',false ,false)
					end
				end
				removeEventHandler("onClientKey", getRootElement(), help_onClientKey)
				destroyElement( help.info)
				destroyElement( help.infoa)
				guiSetPosition ( help.window, (screenWidth-550)/2, (screenHeight-350)/2, false)
				guiGridListSetItemText (help.edit.set[1],help.edit.set[2],help.edit.set[3],button,false ,false)
				help_onClientUpdate()
			end
		end
	end
	
	
	function help_window_request()
		if help.window  then
			showCursor(false)
			removeEventHandler ( "onClientGUIClick",help.close, accept )	
			removeEventHandler ( "onClientClick",getRootElement() , bring )	
			removeEventHandler( "onClientGUIDoubleClick", help.grid_settings, help_window_click )	
			destroyElement(help.window )
			help = {}
			_client_panel_save()
			functionToBindOtherFunctions()
			return false
		end
		help.window = guiCreateWindow ((screenWidth-550)/2, (screenHeight-350)/2, 550, 350, "A/D Aspect 1.0.4: help panel.",false )
		help.tab = guiCreateTabPanel ( 0.01, 0.06, 0.98, 0.93, true, help.window )
		help.about = guiCreateTab ( "About", help.tab )
		help.logo = guiCreateStaticImage (0.0, 0.00, 1, 0.5, "img/b_logo.png", true, help.about )

		help.aboutMemo = guiCreateMemo ( 0.00, 0.45, 1, 0.55, "\n	A/D Aspect it's a Attack/Defend type of game mode for Multi Theft Auto: San Andreas, written in lua.\n\
	Was created for professional clan matches with attention to clean game and playinign with rules.\n\
	It's based on BaseMode ( my previous project ), but with coincidence of time almost completely been changed to other gamemode,\
	in comparison with basemode source code differs in more than 90%.\n\
	It is very well optimized and programmed for the latest versions of the Multi Theft Auto.\n\
	\n\
	It's very powerful and has many features:\n\
	  - expanded configuration panel,\n\
	  - restore feature ( with saving position, weapons, vehicles, health etc ) available as /restore command ( only in match mode ),\n\
	  - detection modified files in gta3.img ( with the exception of weapons textures and weapons models resembling in size to original models ),\n\
	  - kicks for ping, fps and packet loss abousing,\n\
	  - info box with important informations,\n\
	  - match feature ( uniform settings of weapons and vehicles, addition features available only in this mode) available as /startmatch [base/tdm] [rouds] command,\n\
	  - client panel ( with client settings and key binds ),\n\
	  - globally client statistics saved on clients disk,\n\
	  - auto pause feature ( auto pause when player got time out durring match ) available in match mode,\n\
	  - map viewer available as /view command,\n\
	  - vote for maps available as /vote [base/arena] command.\n\
	  - preview of commands usage of players visible on chat ( only in match mode),\n\
	  - preview of started resources visible on chat ( only in match mode),\n\
	  - detection of fake times outs ( only in match mode),\n\
	  - expanded teams, weapons, vehiles, and spawns selectors,\n\
	  - expanded spectator,\n\
	  - anti helli-kill and car kill available as settings in configuration panel,\n\
	  - built-in scripts 'reload' and 'injury',\n\
	  - possibility to do screenshot from game to each player on server available as /screen command,\n\
	  - report system for reporting issues available as /report\n\
	  - call help system default available as H key,\n\
	  - and many more minor features,\n\
	\n\
	Full command list:\n\
	\n\
	/pm [id] - private message\n\
	/arena [id] - for starting arenas\n\
	/base [id] - for starting bases\n\
	/end - for ending the round\n\
	/add [id] - for adding the player to round\n\
	/resetscore - restart all players and teams score\n\
	/gunmenu [id] - for giving the gunmenu for the player\n\
	/remove [id] - for removing the player from the round\n\
	/screen id quaility(0-100) [taq] [width] [height] - for doing screenshot for the player\n\
	/vote [base/arena] [id/ids] - for start the voting\n\
	/car [id] - for get the vehicle in main lobby\n\
	/clean - for restart the rounds history\n\
	/pause - for pausing/repausing the round\n\
	/swap -  for change the teams sides\n\
	/tp [id1] [id2] -  for teleport the player1 to the player2\n\
	/heal [id] - for heal the player\n\
	/healall - for heal all players\n\
	/startmatch [base/tdm] [rounds] - for starting the match\n\
	/endmatch - for ending the match\n\
	/gun - re weapon select\n\
	/rsp - for re-sync\n\
	/view - for viewing the maps\n\
	\n\
	Defaults binds:\n\
	\n\
	F1 - configuration panel\n\
	F3 - client panel\n\
	F4 - re-select team\n\
	H - call help\n\
	R - Realod the weapon\n\
	\n\
	 www.mate.unixstorm.org\
	\n\
	* Copyright 2011-2012 by 'Mate_", true, help.about )
		guiMemoSetReadOnly ( help.aboutMemo, true )
	--	help.txt1 = guiCreateLabel ( 0.57, 0.031, 0.42, 0.2, "A/D Aspect it is a Attack/Defend type \ngamemodefor Multi Theft Auto, written \nin lua. ", true, help.about )
	--	guiSetFont ( help.txt1, 'default-bold-small' )
		help.rules = guiCreateTab ( "Rules", help.tab )
		help.rulesMemo = guiCreateMemo ( 0.00, 0.00, 1, 1, "\
   Rules from 05/03/2012\n\
   Failure to rules threatens ban on gamemode ( applies to individual players and also clans ). \n\
**** Generaly: ****\n\
   1. To begin the match it is necessary to use the command /startmatch [base/tdm] [rounds]. Otherwise, the match isn't officially valid.\n\
   2. Using any type of cheats, bugs, game boosters, mods helping you in gameplay is not allowed.\n\
   3. Limits:\n\
    - minimum fps 25,\n\
    - minimum packet loss 0% - 8.5%,\n\
    - maximum ping:\n\
      a) globally - 0 - 550 ( players from different countries far apart from each other ).\n\
      b) locally  - 0 - 150 ( players from the same country or neighbouring countries).\n\
   4. Inflating pings / decreasing fps is not allowed.\n\
   5. Heli boom - allowed ( the script changes an explosion into the same as car's one ).\n\
   6. Exploding grenade which deals damage through a wall, isn't classified as a bug!\n\
   \n\
**** Game: ****\n\
  ** A/D ( Bases ): **\n\
   1. Gameplay variants: 7 rounds ( 6 bases, 1 tdm ), 9 rounds ( 8 bases, 1 tdm ).\n\n\
   2. The bases are chosen automatically by an algorithm which generates a random base. In order for this to occur, just type the command /base.\n\
   3. Car rush is allowed on all kind of bases.  \n\
   4. Only arena 2 is played as tdm.\n\
   5. FPS Limit 45-47.\n\
   6. Allowed kind of crouch bug: 'alternative' and 'default'.\n\
   7. The team wins through:\n\n\
    - Bases:\n\
     * capturing the marker ( Attack ),\n\
     * killing all enemy team ( both ),\n\
     * end of time and base has not been captured ( Defence ),\n\
    - Arena:\n\
	 * killing all enemy team\n\
     * end of time and when:\n\
       a) they have more people alive than enemy,\n\
       b) when there is the same number of players, team who has more health point wins the round, \n\
       c) tie when both of teams have the same number of players and health point.\n\
  ** TDM: **\n\
     existing rules on Russian League and etc :D", true, help.rules )
		guiMemoSetReadOnly ( help.rulesMemo, true )
		help.history = guiCreateTab ( "Round History", help.tab )
		help.info = guiCreateTab ( "Server", help.tab )
		help.cmds = guiCreateTab ( "Cmds log", help.tab )
		help.settings = guiCreateTab ( "Settings", help.tab )
		help.stats = guiCreateTab ( "Stats", help.tab )
		help.close = guiCreateButton ( 0.95, 0.06, 0.05, 0.06, "X", true, help.window )
		callServer("help_window", getLocalPlayer() )
	end
	
	view_t = {size=math.min(1,yhy2(900,1)),des="",ren={getScreenPositionByRelative(0.25,0.9)},ren1={getScreenPositionByRelative(0.35,0.03)},ren2={getScreenPositionByRelative(0.2,0.93)}}
	
	function view_windowKeys()
		if source == view_t.view then
			local get_name = guiGetText(view_t.edit)
				if get_name == false or get_name == "" then
					return false
				end	
			local char = string.find(get_name, "_") 
			local typem = string.sub(get_name,1,char-1)
			local id = string.sub(get_name,char+1)
			callServer("view_start",getLocalPlayer(),typem,id)	
		elseif source == view_t.vt then
		local get_name = guiGetText(view_t.edit)
			if get_name == false or get_name == "" then
				return false
			end	
			if string.find(get_name, ",") then
			local table_t = {}
				for i=1,1000 do
					local value = gettok ( get_name, i, string.byte(',') )
						if value ~= false then
							local char = string.find(value, "_") 
							local typem = string.sub(value,1,char-1)
							local id = string.sub(value,char+1)
							table.insert( table_t , {typem,id} )
						else
							callServer("create_svote",getLocalPlayer(),table_t)	
							break
						end
				end
			else
				local char = string.find(get_name, "_") 
				local typem = string.sub(get_name,1,char-1)
				local id = string.sub(get_name,char+1)
				callServer("create_svote",getLocalPlayer(),{{typem,id}})	
			end
			
			
			
			
		elseif source == view_t.start then
		local get_name = guiGetText(view_t.edit)
			if get_name == false or get_name == "" then
				return false
			end	
		local char = string.find(get_name, "_") 
		local typem = string.sub(get_name,1,char-1)
		local id = string.sub(get_name,char+1)
			callServer("Start",getLocalPlayer(),typem,id)
		elseif  source == view_t.close then
			view_close()
		elseif  source == view_t.all then
			callServer("view_window", getLocalPlayer(),0 )
		elseif  source == view_t.arena then
			callServer("view_window", getLocalPlayer(),2 )
		elseif  source == view_t.base then
			callServer("view_window", getLocalPlayer(),1 )
		elseif  source == view_t.list then
			--[[local get_id  =  guiGridListGetSelectedItem ( view_t.list )
			if get_id  ~= -1  then
				local name = guiGridListGetItemText ( view_t.list, get_id  , 1 )
				guiSetText(view_t.edit,name)
			end]]
			local name_f = ""
			local s_itmes = guiGridListGetSelectedItems (  view_t.list )
			if #s_itmes > 1 then
				for k,v in ipairs(s_itmes) do
					local name = guiGridListGetItemText ( view_t.list, v["row"]  , 1 )
					name_f = name_f..""..name..","
				end
				guiSetText(view_t.edit,name_f)
			else
				local get_id  =  guiGridListGetSelectedItem ( view_t.list )
				if get_id  ~= -1  then
					local name = guiGridListGetItemText ( view_t.list, get_id  , 1 )
					guiSetText(view_t.edit,name)
				end
			end
		end
	end
	
	function view_window(cmd,vote_mode)
		if view_t.window or getElementData ( sett,"Round" ) ~= 0 then
			return false
		end
		view_t.vote = vote_mode
		view_t.window = guiCreateWindow ((screenWidth-400)/2, (screenHeight-350)/2, 400, 350, vote_mode or "Map viewer.",false )
		guiSetAlpha(view_t.window,0)
		view_t.all = guiCreateRadioButton ( 0.1, 0.05, 0.1, 0.1, "All",  true, view_t.window )
		view_t.arena = guiCreateRadioButton ( 0.25, 0.05, 0.3, 0.1, "Show only arenas",   true, view_t.window )
		view_t.base = guiCreateRadioButton ( 0.6, 0.05, 0.3, 0.1, "Show only bases",   true, view_t.window )
		guiRadioButtonSetSelected ( view_t.all, true )
		view_t.edit = guiCreateEdit ( 0.025, 0.15,0.95, 0.06, "",  true, view_t.window )
		view_t.list = guiCreateGridList ( 0.025, 0.22, 0.95, 0.68, true, view_t.window )
		guiGridListAddColumn ( view_t.list ,"maps", 0.9 )
		callServer("view_window", getLocalPlayer(),0 )
		if view_t.vote ~= nil then
			view_t.vt = guiCreateButton ( 0.025, 0.915, 0.625, 0.11, "Vote", true, view_t.window  )	
			local GX,GY = guiGetPosition(view_t.window,true )
			view_t.t_i = guiCreateLabel ( GX+0.035,GY-0.035, 0.25, 0.1, "Hold CTRL to select multiple maps.",true )
			guiLabelSetColor (view_t.t_i,0,0,0 )
			view_t.t_i2 = guiCreateLabel ( 2,2, 500, 500, "Hold CTRL to select multiple maps.",false,view_t.t_i )
			guiSetFont(view_t.t_i ,fontfonrt3)
			guiSetFont(view_t.t_i2 ,fontfonrt3)
			--guiLabelSetColor (view_t.t_i,225,225,225 )
		else	
			view_t.view = guiCreateButton ( 0.025, 0.915, 0.3, 0.11, "View", true, view_t.window  )
			view_t.start = guiCreateButton ( 0.35, 0.915, 0.3, 0.11, "Start", true, view_t.window  )
		end
		view_t.close = guiCreateButton ( 0.675, 0.915, 0.3, 0.11, "Close", true, view_t.window  )
		addEventHandler ( "onClientGUIClick",view_t.vt  , view_windowKeys, true )	
		addEventHandler ( "onClientGUIClick",view_t.view , view_windowKeys, true )	
		addEventHandler ( "onClientGUIClick",view_t.start , view_windowKeys, true )	
		addEventHandler ( "onClientGUIClick",view_t.close , view_windowKeys, true )	
		addEventHandler ( "onClientGUIClick",view_t.all , view_windowKeys, true )	
		addEventHandler ( "onClientGUIClick",view_t.arena , view_windowKeys, true )	
		addEventHandler ( "onClientGUIClick",view_t.base , view_windowKeys, true )	
		addEventHandler ( "onClientGUIClick",view_t.list , view_windowKeys, true )	
	end
	addCommandHandler("view",view_window)
	
	function view_windowLoad(list,typel)
	--	outputChatBox(typel)
		guiGridListClear ( view_t.list )
			if view_t.vote ~= nil then
				guiGridListSetSelectionMode ( view_t.list, 1 )
			else
				guiGridListSetSelectionMode ( view_t.list, 0 )
			end
		if typel == 0 or typel ==  1 then
			for key,Name in ipairs(list.base) do
				local row = guiGridListAddRow (view_t.list )
				guiGridListSetItemText ( view_t.list, row, 1, Name, false, false )
			end
		end	
		if typel == 0 or typel ==  2 then
			for key,Name1 in ipairs(list.arena) do
				local row = guiGridListAddRow (view_t.list )
				guiGridListSetItemText ( view_t.list, row, 1, Name1, false, false )
			end
		end
		guiGridListSetSelectedItem ( view_t.list, 0, 1 )	
		guiSetAlpha(view_t.window,1)
		showCursor(true)
	end
	
	
	function view_frecam(x,y,z,int,des)
		call(getResourceFromName("freecam"), "setFreecamOption", "normalMaxSpeed",0.7)
		call(getResourceFromName("freecam"), "setFreecamOption", "fastMaxSpeed ",5)
		call(getResourceFromName("freecam"), "setFreecamEnabled")
		view_t.marker = createMarker ( x,y,z, "cylinder", 2, 16, 78, 139, 180 )
		syncInterior(getLocalPlayer(),int)
		setCameraMatrix(x,y,z+1 ,x,y,z)
		showCursor(false)
		guiSetPosition(view_t.window,screenWidth,screenHeight,false)
		bindKey("enter","up",view_back)
		if des then
			view_t.des = des
		else
			view_t.des = ""
		end
		addEventHandler("onClientRender", getRootElement(), view_render)
	end	
	
	function view_render ()
		dxDrawTextBaQ(view_t.des, view_t.ren1[1], view_t.ren1[2],screenWidth, screenHeight, colors_g.gray, view_t.size,  "bankgothic", "default-bold", "left", "top",false, false, true) 
		dxDrawTextBaQ("Press Enter to return to the previous gui.", view_t.ren[1], view_t.ren[2],screenWidth, screenHeight, colors_g.gray, view_t.size,  "bankgothic", "default-bold", "left", "top",false, false, true) 
			dxDrawText("Free cam mode is enabled, use keyboard keys ( forwards, backwards, left, right, shift ) and mouse to move camera.", view_t.ren2[1], view_t.ren2[2],screenWidth, screenHeight, colors_g.gray, 0.6,  "bankgothic", "default-bold", "left", "top",false, false, true) 
	end

	function view_close()
		removeEventHandler ( "onClientGUIClick",view_t.vt  , view_windowKeys)
		removeEventHandler ( "onClientGUIClick",view_t.view , view_windowKeys)
				removeEventHandler ( "onClientGUIClick",view_t.start , view_windowKeys)
					removeEventHandler ( "onClientGUIClick",view_t.close , view_windowKeys)
						removeEventHandler ( "onClientGUIClick",view_t.all , view_windowKeys)
							removeEventHandler ( "onClientGUIClick",view_t.arena , view_windowKeys)
						removeEventHandler ( "onClientGUIClick",view_t.base , view_windowKeys)
					removeEventHandler ( "onClientGUIClick",view_t.list , view_windowKeys)
				destroyElement(view_t.window)
				if isElement(view_t.t_i) then destroyElement(view_t.t_i) end
				showCursor(false)
			view_t = {size=math.min(1,yhy2(900,1)),des="",ren={getScreenPositionByRelative(0.25,0.9)},ren1={getScreenPositionByRelative(0.35,0.03)},ren2={getScreenPositionByRelative(0.2,0.93)}}
			if isElement(view_t.marker) then
				destroyElement(view_t.marker)
			end
			call(getResourceFromName("freecam"), "setFreecamDisabled")
			if getElementData (sett,"Round" ) == 0 and view_t.vote ~= nil then
				syncInterior(getLocalPlayer(),0 )
				setCameraTarget(getLocalPlayer())
				callServer("ChangePlayerTeam", getLocalPlayer(),getPlayerTeam(getLocalPlayer()))	
			end
		view_t = {size=math.min(1,yhy2(900,1)),des="",ren={getScreenPositionByRelative(0.25,0.9)},ren1={getScreenPositionByRelative(0.35,0.03)},ren2={getScreenPositionByRelative(0.2,0.93)}}	
	end
	function view_back()
		destroyElement(view_t.marker)
		removeEventHandler("onClientRender", getRootElement(), view_render)
		unbindKey("enter","up",view_back)
		call(getResourceFromName("freecam"), "setFreecamDisabled")
		guiSetPosition(view_t.window,(screenWidth-400)/2, (screenHeight-350)/2,false)
		showCursor(true)
		callServer("stopYourResource", getLocalPlayer() )
	end
	--[[ How crash the game? use this:
			help.window = guiCreateWindow ((screenWidth-550)/2, (screenHeight-350)/2, 550, 350, "A/D Aspect 1.0: help panel.",false )
		guiCreateTab ( "asd", help.window )
		guiCreateTab ( "dsa", help.window )
	]]
	
	local got_points_t = {}
	
	function got_points(points,reason,name)
		if got_points_t.tc  then
			removeEventHandler("onClientRender",getRootElement(),got_points_render)
		end
		got_points_t = {size=math.min(1.6,math.max(yhy2(900,1),0.7)),size2=math.min(1.3,math.max(yhy2(900,0.7),0.4)),pos1={getScreenPositionByRelative(0.47,0.65)},pos2={getScreenPositionByRelative(0.44,0.69)},pos3={getScreenPositionByRelative(0.44,0.69)}}
			if points ~= false then
				got_points_t.data = {'+'..tostring(points),reason,' '..name}
			else
				got_points_t.data = {'',reason,' '..name}
			end
		got_points_t.pos1[1] =  (screenWidth - dxGetTextWidth ( got_points_t.data[1], got_points_t.size ,"bankgothic" ))/2
		got_points_t.pos2[1] =  (screenWidth - (dxGetTextWidth ( got_points_t.data[2], got_points_t.size2 ,"bankgothic" ) + dxGetTextWidth ( got_points_t.data[3], got_points_t.size2 ,"bankgothic" )))/2
		got_points_t.pos3[1] = got_points_t.pos2[1] + dxGetTextWidth ( got_points_t.data[2], got_points_t.size2 ,"bankgothic" )
		got_points_t.tc = getTickCount()
		addEventHandler("onClientRender",getRootElement(),got_points_render)
		if points ~= false then
			client_settings[13] = tonumber(client_settings[13] ) + points
			setElementData ( localPlayer,"Score", (getElementData ( localPlayer,"Score"  )or 0) + points  )	
		end
	end
	
	function got_points_render()
		local r = math.random(1,2)
		dxDrawText (got_points_t.data[1], got_points_t.pos1[1]+2, got_points_t.pos1[2]+2 , 0, 0,colors_g.black, got_points_t.size ,"bankgothic") 
		dxDrawText (got_points_t.data[1], got_points_t.pos1[1], got_points_t.pos1[2] , 0, 0,colors_g.gray,got_points_t.size ,"bankgothic") 
		dxDrawText (got_points_t.data[2], got_points_t.pos2[1]+2, got_points_t.pos2[2]+2 , 0, 0,colors_g.black,got_points_t.size2 ,"bankgothic") 
		dxDrawText (got_points_t.data[2], got_points_t.pos2[1], got_points_t.pos2[2] , 0, 0,colors_g.lblue,got_points_t.size2 ,"bankgothic")
 		dxDrawText (got_points_t.data[3], got_points_t.pos3[1]+2, got_points_t.pos3[2]+2 , 0, 0,colors_g.black,got_points_t.size2 ,"bankgothic") 
		dxDrawText (got_points_t.data[3], got_points_t.pos3[1], got_points_t.pos3[2] , 0, 0,colors_g.gray,got_points_t.size2 ,"bankgothic") 
		if getTickCount() - got_points_t.tc > 5000 then
			removeEventHandler("onClientRender",getRootElement(),got_points_render)
			got_points_t = {}
		end
	end
functionToBindOtherFunctions()



	local restore_ = {}
	function restore_window_request(cmd,id)
		if restore_.window  then
			return false
		end
		if getElementData ( sett,"Round" ) == 0 then
		outputChatBox ( "#FF0000** Error:#0AC419 This command works only durring round.",255, 255, 255, true )
			return false
		end
		if logget_out == nil then
			outputChatBox ( "#FF0000** Error:#0AC419 you are not admin.",255, 255, 255, true )
			return false
		end
		restore_.window = guiCreateWindow ((screenWidth-550)/2, (screenHeight-350)/2, 550, 350, "A/D Aspect Reloaded 1.0.6: resotre panel.",false )
		guiSetAlpha(restore_.window,0)
		restore_.grid = guiCreateGridList (  0.025, 0.075, 0.95, 0.8 ,true, restore_.window)
		guiGridListAddColumn ( restore_.grid , 'Name', 0.25 )
		guiGridListAddColumn ( restore_.grid , 'Time', 0.15 )
		guiGridListAddColumn ( restore_.grid , 'Postion (Zone)', 0.22 )
		guiGridListAddColumn ( restore_.grid , 'Health', 0.12 )
		guiGridListAddColumn ( restore_.grid , 'Type', 0.22 )
		restore_.restore = guiCreateButton ( 0.025, 0.89, 0.462, 0.075, "Restore", true, restore_.window )
		restore_.close = guiCreateButton ( 0.5125, 0.89, 0.462, 0.075, "Close", true, restore_.window )
		callServer("restore_window", getLocalPlayer(),id )
	end
	addCommandHandler("restore",restore_window_request)
	
	function restore_window(t,player)
	if isElement(player) == false or #t == 0 then
			removeEventHandler ( "onClientGUIClick",getRootElement(),  restore_click)	
			destroyElement(restore_.window)
			restore_ = {}
			showCursor(false)
			return false
	end
		for k, v in pairs(t) do
			local row = guiGridListAddRow (restore_.grid )
				guiGridListSetItemText ( restore_.grid, row, 1,v.name, false, false )
				guiGridListSetItemText ( restore_.grid, row, 4,v.hp, false, false )
				guiGridListSetItemText ( restore_.grid, row, 2,v.time, false, false )
			--	outputChatBox(tostring(v.pos))
			--	outputChatBox(tostring(v.pos[1]))
				guiGridListSetItemText ( restore_.grid, row, 3,getZoneName ( v.pos[1],v.pos[2],v.pos[3] ), false, false )
				guiGridListSetItemText ( restore_.grid, row, 5,v.reason, false, false )
		end
	restore_.player = player
	guiSetAlpha(restore_.window,1)
	addEventHandler ( "onClientGUIClick",getRootElement(),  restore_click)	
	showCursor(true)
	end
	
	function restore_click()
		if source == restore_.restore then
		local select = guiGridListGetSelectedItem ( restore_.grid )
			if select ~= -1 then
				local name = guiGridListGetItemText ( restore_.grid, select , 1 )
					if name then
						callServer("restore_restore", localPlayer,restore_.player,name )
							destroyElement(restore_.window)
								removeEventHandler ( "onClientGUIClick",getRootElement(),  restore_click)	
							restore_ = {}
						showCursor(false)
					end	
			end
		elseif source == restore_.close then
			removeEventHandler ( "onClientGUIClick",getRootElement(),  restore_click)	
			destroyElement(restore_.window)
			restore_ = {}
			showCursor(false)
		end
	end
	
	local match_t =  {}
	
	function fix_name(n)
		if n == 'Bpb*>' then
			return 'Bpb'
		else
			return n
		end	
	end
	
	function match_start(type_,rounds)
		round_mode = {type_,rounds}
		match_t = {alpha=255,tc=getTickCount(),data={},size=math.min(2.6,math.max(yhy2(900,2.0),1.7)),size2=math.min(1.6,math.max(yhy2(900,1),0.7)),pos1={getScreenPositionByRelative(0.2,0.3)},pos1I={getScreenPositionByRelative(0.2,0.35)},pos2={getScreenPositionByRelative(0.44,0.3)},pos2I={getScreenPositionByRelative(0.44,0.35)},pos3={getScreenPositionByRelative(0.3,0.65)},pos6={getScreenPositionByRelative(0.3,0.85)},pos4={getScreenPositionByRelative(0.3,0.75)},pos5={getScreenPositionByRelative(0.3,0.4)}}
		match_t.data.name1 =  getTeamName( TableTeams[1] )
		match_t.data.name1F = 'img/Flags/'..fix_name( getTeamName( TableTeams[1] ) )..'.png'
		if fileExists ( match_t.data.name1F ) == false then
			match_t.data.name1F = "img/Flags/NO.png"
		end
		local r,g,b = getTeamColor( TableTeams[1] )
		match_t.data.color1 = {r,g,b}
		r,g,b = getTeamColor( TableTeams[2] )
		match_t.data.color2 = {r,g,b}
		match_t.data.name2 = getTeamName( TableTeams[2] ) 
		match_t.data.name2F = 'img/Flags/'..fix_name( getTeamName( TableTeams[2] ) )..'.png'
		if fileExists (match_t.data.name2F ) == false then
			match_t.data.name2F = "img/Flags/NO.png"
		end
		match_t.data.type =  'Match Type: '..type_..'  Match Rounds: '..tostring(rounds)
		local low_res = {512,256}
		if screenHeight < 768 then
		local mn_ = 1.1
			if screenHeight < 481 then
				mn_ = 1.6
			elseif screenHeight < 601 then
				mn_ = 1.3
			end
			for k,v in ipairs(low_res) do
				low_res[k] = math.round(v/mn_,2)
			end
		end
		local mn = math.min(1.5,math.max(yhy2(900,1.0),0.5))
		match_t.images = {low_res[1],low_res[2]}
		round_mode = {type_,tonumber(rounds)}
		match_t.data.info =  '( start frist base to team '..getTeamName( getTeamByType("Defense") ) ..' ( Defense ) )'
		match_t.pos1[1] =  (match_t.images[1]/10) +  (( (screenWidth/2) - dxGetTextWidth (match_t.data.name1, match_t.size ,"bankgothic" ))/2) 	
		match_t.pos2[1] =  ((screenWidth/2) + ( (screenWidth/2) - dxGetTextWidth ( match_t.data.name2,  match_t.size ,"bankgothic" ))/2)  -(match_t.images[1]/10)
		match_t.pos1I[1] =  (match_t.images[1]/10) +  ( (screenWidth/2) - match_t.images[1])/2
		match_t.pos2I[1] =  ((screenWidth/2) + ( ((screenWidth/2) - match_t.images[1]))/2) - (match_t.images[1]/10)
		match_t.pos3[1] =  (screenWidth - dxGetTextWidth ( match_t.data.type,  match_t.size2 ,"bankgothic" ))/2
		match_t.pos4[1] =  (screenWidth - dxGetTextWidth ( match_t.data.info,  match_t.size2 ,"bankgothic" ))/2
		match_t.pos5[1] =  (screenWidth - dxGetTextWidth ( 'VS',  match_t.size*1.5 ,"bankgothic" ))/2
		addEventHandler("onClientRender",getRootElement(),match_render)	
	end 
	
	function match_end()
		round_mode = {'normal',0}
	end
	
	function match_render()
		local black = tocolor(0,0,0,match_t.alpha)
		dxDrawImage ( match_t.pos1I[1] , match_t.pos1I[2], match_t.images[1], match_t.images[2], match_t.data.name1F  )
		dxDrawImage ( match_t.pos2I[1] , match_t.pos2I[2] , match_t.images[1], match_t.images[2], match_t.data.name2F  )
		dxDrawTextBaQ_c(match_t.data.name1, match_t.pos1[1], match_t.pos1[2],screenWidth, screenHeight, tocolor(match_t.data.color1[1],match_t.data.color1[2],match_t.data.color1[3],match_t.alpha), match_t.size,  "bankgothic",black) 
		dxDrawTextBaQ_c(match_t.data.name2, match_t.pos2[1], match_t.pos2[2],screenWidth, screenHeight, tocolor(match_t.data.color2[1],match_t.data.color2[2],match_t.data.color2[3],match_t.alpha), match_t.size,  "bankgothic",black) 
		local gray = tocolor(200,200,200,match_t.alpha)
		dxDrawText_sh(match_t.data.type, match_t.pos3[1], match_t.pos3[2],screenWidth, screenHeight, gray, match_t.size2,  "bankgothic",black) 
		dxDrawText_sh(match_t.data.info, match_t.pos4[1], match_t.pos4[2],screenWidth, screenHeight, gray, match_t.size2,  "bankgothic",black) 
		--dxDrawText_sh(match_t.data.rounds, match_t.pos6[1], match_t.pos6[2],screenWidth, screenHeight, gray, match_t.size2,  "bankgothic",black) 
		dxDrawTextBaQ_c('VS', match_t.pos5[1], match_t.pos5[2],screenWidth, screenHeight, colors_g.red, match_t.size*1.5,  "bankgothic",black) 
		if getTickCount() - match_t.tc > 8500 then
			removeEventHandler("onClientRender",getRootElement(),match_render)
			match_t =  {}
		elseif getTickCount() - match_t.tc > 6500 then
			match_t.alpha = 255 - ((getTickCount() - (match_t.tc+6500) ) * (255/2000))
	--	255-((  getTickCount() -anim_.time2)*anim_.add)
		end
	end
	--setTimer(function() match_start('Base') end,500,1)
	
	
	

	--///////////////////////////////////////////////
	
	

	--// AC
	
	Selectors = {}
	Selectors[1] = false
	Selectors[2] = false
	Selectors[3] = false
	function getPointFromDistanceRotation(x, y, dist, angle)
	 
		local a = math.rad(90 - angle);
	 
		local dx = math.cos(a) * dist;
		local dy = math.sin(a) * dist;
	 
		return x+dx, y+dy;
	 
	end
	function findRotation(x1,y1,x2,y2)
	 
	  local t = -math.deg(math.atan2(x2-x1,y2-y1))
	  if t < 0 then t = t + 360 end;
	  return t;
	 
	end


	function isNot(s)
	local wrong = {
	9, 10, 11, 12, 13, 31, 32, 33, 38, 39, 40, 41, 43, 44, 53, 54, 55, 56, 58, 
	63, 64, 69, 75, 76, 77, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 112, 129, 130, 
	131, 132, 134, 136, 137, 138, 139, 140, 141, 145, 148, 150, 152, 157, 160, 162,
	169, 172, 178, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 201, 207, 
	209, 210, 211, 212, 214, 215, 216, 218, 219, 224, 225, 226, 229, 230, 231, 
	232, 233, 234, 235, 236, 237, 238, 243, 244, 246, 251, 252, 253, 256, 257, 261, 263}
		for i=1,#wrong do
			if s == wrong[i] then
				return false
			end
		end
		return true
	end


	function _cheat_detec(t)
		if game_settings.anticheat[1] == "simple" or game_settings.anticheat[1] == "simple with notifications" then
			for k,v in pairs(t) do
				checkExcepts_s(v.name,v.sizeX ,v.sizeY ,v.sizeY)
			end	
			
			--sniper_anim.dff itd itd
		-- podmiana broni
		-- wykrywanie itp broni
		end
		if game_settings.anticheat[1] == "simple with notifications" then
		local lines_ = {current=1}
			for k,v in pairs(t) do
				checkExcepts_s(v.name,v.sizeX ,v.sizeY ,v.sizeY) 
					if lines_[lines_.current] then
						lines_[lines_.current] = lines_[lines_.current]..", "..v.name
							if #lines_[lines_.current] > 100 then
								lines_.current = lines_.current+1
							end
					else
						lines_[lines_.current] = v.name
					end
			end
			callServer("outputChatBox", "#FF0000[#0AC419AC##FF0000simple with notifications]#0AC419  Player: #FF0000"..getPlayerName( localPlayer ).. "#0AC419  have moded files:",getRootElement(), 255, 255, 255, true)
			for k,v in ipairs(lines_) do
				callServer("outputChatBox", "#FF8C00"..v,getRootElement(), 255, 255, 255, true )
			end
		elseif game_settings.anticheat[1] == "full" then
			for k,v in pairs(t) do
				if checkExcepts(v.name) == false and checkExcepts_s(v.name,v.sizeX ,v.sizeY ,v.sizeY) == true then
					callServer("kickPlayer", Local, "[AC# profle: full] Moded files: "..v.name..". Please reinstal game to play." )
				end
			end
		elseif game_settings.anticheat[1] == "extreme" then
			callServer("kickPlayer", Local, "[AC# profle: extreme] Moded file: "..t[1].name..". Please reinstal game to play." )
		end
	end

	function checkExcepts(name)
	local exceps = {'gun_para.txd','grenade.txd','knifecur.txd','molotov.txd','colt45.txd','teargas.txd','silenced.txd','sniper.txd','desert_eagle.txd','chromegun.txd','cuntgun.txd','sawnoff.txd','sawnoff.dff','m4.txd','shotgspa.txd','ak47.txd','micro_uzi.txd','tec9.txd','mp5lng.txd','minigun.txd','minigun.dff'}
		for k1,v1 in pairs(exceps) do 
			if name == v1 then
				return true
			end
		end
		if string.find(name, ".txd") ~= nil and string.find(name, "radar") == 1 and #name < 13 then --// wyjatek radarXXX.txd
			return true
		end
		return false
	end

	

	
	function checkExcepts_s(name,x,y,z)
		local excep_ = {
			--// name 			X	 Y	  Z		%
			['grenade.dff'] = {0.08, 0.09, 0.14, 0.0, 0.0, 0.0},
			['teargas.dff'] = {0.11, 0.07, 0.2, 0.0, 0.0, 0.0},
			['molotov.dff'] = {0.09, 0.09, 0.38, 0.0, 0.0, 0.0},
			['sniper.dff'] = {1.49, 0.15, 0.24, 1.2,1.5,1.5},
			['m4.dff'] = {1.82, 0.35, 0.31, 1.2,1.5,1.5},
			['ak47.dff'] = {1.24, 0.46, 0.45,  1.25,1.4,1.4},
			['tec9.dff'] = {1, 0.35, 0.37, 1.15,1.4,1.5},
			['knifecur.dff'] = {0.11, 0.05, 0.41, 1.2,1.5,1.3},
			['chromegun.dff'] = {2.03, 0.19, 0.32, 1.2,1.5,1.4},
			['mp5lng.dff'] =  {1, 0.35, 0.4, 1.3,1.5,1.4},
			['desert_eagle.dff'] =  {0.55, 0.15, 0.22 , 1.3,1.5,1.5},
			['silenced.dff'] =  {0.6, 0.09, 0.2, 1.3,1.5,1.5},
			['cuntgun.dff'] =  {2, 0.19, 0.31, 1.2,1.5,1.5},
			['shotgspa.dff'] =  {0.95, 0.19, 0.34, 1.2,1.5,1.5},
			['micro_uzi.dff'] =  {1, 0.35, 0.4, 1.2,1.5,1.5},
			['colt45.dff'] =  {0.44, 0.15, 0.21, 1.3,1.5,1.5},
		}
		if type(excep_[name]) ~= 'table' and x == nil or y == nil or z == nil then
			return true
		end
		
		for k1,v1 in pairs( excep_) do 
			if name == k1 then
			if x > ( v1[1] * v1[4] ) or y > ( v1[2] * v1[5] ) or z > ( v1[3] * v1[6] ) then
			
				local to_replace = {
					['grenade.dff'] = {"grenade.txd",342},
					['teargas.dff'] = {"teargas.txd",343},
					['molotov.dff'] = {"molotov.txd",344},
					['sniper.dff'] = {"sniper.txd",358},
					['m4.dff'] = {"m4.txd",356},
					['ak47.dff'] = {"ak47.txd",355},
					['tec9.dff'] = {"tec9.txd",372},
					['knifecur.dff'] = {"knifecur.txd",335},
					['chromegun.dff'] = {"chromegun.txd",349},
					['mp5lng.dff'] =  {"mp5lng.txd",353},
					['desert_eagle.dff'] =  {"desert_eagle.txd",348},
					['silenced.dff'] =  {"silenced.txd",347},
					['cuntgun.dff'] =  {"cuntgun.txd",357},
					['shotgspa.dff'] =  {"shotgspa.txd",351},
					['micro_uzi.dff'] =  {"micro_uzi.txd",352},
					['colt45.dff'] =  {"colt45.txd",346},
					--	['minigun.dff'] =  "minigun.txd",
					--	['sawnoff.dff'] =  "sawnoff.txd",
					}
					engineRestoreModel ( to_replace[name][2] )
					local txd,dff = false,false
					if name == 'sniper.dff' and fileExists ( 'userfiles/sniper.txd' ) == true then
						for i=1,3 do
							txd = engineLoadTXD ( 'userfiles/sniper.txd' )
							dff = engineLoadDFF ( "others/weapons/"..name, to_replace[name][2] )
							engineImportTXD ( txd, to_replace[name][2] )
							engineReplaceModel ( dff, to_replace[name][2] )	
						end					
					else
						for i=1,3 do
							txd = engineLoadTXD ( "others/weapons/"..to_replace[name][1] )
							dff = engineLoadDFF ( "others/weapons/"..name, to_replace[name][2] )
							engineImportTXD ( txd, to_replace[name][2] )
							engineReplaceModel ( dff, to_replace[name][2] )	
						end
					end
					if dff == false then
						return true
					else
						replace_m[to_replace[name][2]] = {dff,txd}
					end	
				end
			end
		end
		return false
	end


	
	--// CBUG
	
	local _a_tc_olo = getTickCount()
	local core_cbug = ''

	function _core_crouchBug()
	--	outputChatBox('FFMy Wave: '..tostring( game_settings.global[5] ).. " "..tostring(core_cbug))
		if game_settings.global[5] == 'alternative' then
			if core_cbug ~= 'alternative' then
				_core_acbug(true)
				core_cbug = game_settings.global[5]
			end
		else
			if core_cbug == 'alternative' then
				_core_acbug(false)
				core_cbug = game_settings.global[5]
			end
		end
	end
	
	local _core_cbug = {}
	
	function _core_acbug(bol)
		if bol == true then
	--		_core_cbug = {lastslot=0,timers=false,enable=true,ids={[24]=450},times={[24]=500},lasttime=getTickCount(),cbug=getTickCount()}
		--	_core_cbug = {on=1,lastslot=0,timers=false,enable=true,ids={[24]=550,[25]=550,[33]=100,[34]=100},times={[24]=500,[25]=300,[33]=250,[34]=250},sprint={[24]=250,[25]=250,[33]=200,[34]=200},lasttime=getTickCount(),cbug=getTickCount()}
			_core_cbug = {ena_b=false,c_t_=getTickCount(),_sp=0,on=1,lastslot=0,timers=false,enable=true,ids={[24]=550,[25]=550,[33]=600,[34]=600},times={[24]=500,[25]=800,[33]=250,[34]=800},sprint={[24]=500},lasttime=getTickCount(),cbug=getTickCount()}
			addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), _core_fire)
			addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), disableMinigunOnSwitch )
		--	bindKey ( "next_weapon","down",_core_switch )
		--	bindKey ( "previous_weapon","down",_core_switch )
			bindKey ( "crouch","down",_core_crouch )
			bindKey ( "aim_weapon","down",_core_aim )
			bindKey ( "aim_weapon","up",_core_aim2 )
		--	bindKey ( "sprint","down",_on_spirnt )
		--	toggleControl ( 'sprint', false )	
		--	addEventHandler("onClientRender", getRootElement(),_on_sprint_r)
		--	outputChatBox('My Wave ON')
			bindKey ( "sprint","down", _on_spirnt_s)
			bindKey ( "sprint","up", _on_sprint_e)
			toggleControl ( 'sprint', false )
		else
	--		outputChatBox('My Dave OFF')
			removeEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), _core_fire)
			removeEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), disableMinigunOnSwitch )
			unbindKey ( "next_weapon","down",_core_switch )
			unbindKey ( "previous_weapon","down",_core_switch )
			unbindKey ( "crouch","down",_core_crouch )
			unbindKey ( "aim_weapon","down",_core_aim )
			unbindKey ( "aim_weapon","up",_core_aim2 )
		--	unbindKey ( "sprint","down",_on_spirnt )
			_core_cbug = {}
			toggleControl ( 'fire', true )
			toggleControl ( 'next_weapon', true )
			toggleControl ( 'previous_weapon', true )
			toggleControl ( 'crouch', true )	
			toggleControl ( 'sprint', true )	
			unbindKey ( "sprint","down", _on_spirnt_s)
			unbindKey ( "sprint","up", _on_sprint_e)
			toggleControl ( 'sprint', true )	
		--	removeEventHandler("onClientRender", getRootElement(),_on_sprint_r)
		end
	end
	
	function _core_aim()
		--toggleControl ( 'sprint', false )	
		--outputChatBox('dodaje '..getTickCount())
		setControlState (  'sprint',false )
		setControlState (  'sprint',false )
		setControlState (  'sprint',false )
		setControlState (  'sprint',false )
	end	
	function _core_aim2()
		--if  _core_cbug._sp == 0 then
		local wtf = getBoundKeys ( "sprint" )
		for k,v in pairs(wtf) do
			if getKeyState ( k ) == true then
				_on_spirnt_s()
				return false
			end
		end	
			--outputChatBox('usuwam '..getTickCount())
		--end
	end
	


	local dsaadasdadsasd = getTickCount()
	local dovakin 
	function _core_fire(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement)
	_core_cbug.ena_b=true
	--outputChatBox(getWeaponNameFromID(weapon)..'    '..tostring( getTickCount()-dsaadasdadsasd).. ' '.. tostring( _core_cbug.enable )..' ' ..tostring(_core_cbug.ids[weapon]))
	dsaadasdadsasd = getTickCount()
		if weapon ~= 16 then
			if _core_cbug.enable == true and _core_cbug.ids[weapon] then
				_core_cbug.ena_b=true
			--	outputChatBox(tostring( getTickCount()-_core_cbug.lasttime))
				_core_cbug.enable = false
			--	toggleControl ( 'fire', false )
				--toggleControl ( 'next_weapon', false )
			--	toggleControl ( 'previous_weapon', false )
				
				_core_cbug._sp = 1
			--	outputChatBox('ustawiam '..getTickCount())
				dovakin = setTimer(function() _core_cbug.enable = true end,_core_cbug.ids[weapon] ,1)
				_core_cbug.cbug = _core_cbug.ids[weapon]
			--	setTimer(function() toggleControl ( 'next_weapon', true ) toggleControl ( 'previous_weapon', true ) end,_core_cbug.times[weapon] ,1)
					--[[if _core_cbug.sprint[weapon] then
						toggleControl ( 'sprint', false )
						setTimer(function() toggleControl ( 'sprint', true )  _core_cbug._sp = 0 end,_core_cbug.sprint[weapon] ,1)
						else
						toggleControl ( 'sprint', true )
					end]]
				_core_cbug.lasttime=getTickCount()
				_core_cbug.lastslot = getPedWeaponSlot ( localPlayer )
			end
		else
			-- dodac blokade zmiany broni po rzucie granatu
		end
	end
	local coun_c = 0
	--[[
	function olololo()
		coun_c = coun_c +1
			if coun_c < 40 then
				setControlState (  'crouch',true )
				if isPedDucked ( localPlayer )  then
					coun_c = 47
				end
			elseif coun_c > 40 and coun_c < 52  then
				setControlState (  'crouch',false )
			else
				removeEventHandler("onClientRender", getRootElement(),olololo)
				coun_c= 0
			--	toggleControl ( 'sprint',true )	
			end
		
	end]]

--[[	function olololo()
		coun_c = coun_c +1
			if coun_c < 30 then
				setControlState (  'crouch',true )
				if isPedDucked ( localPlayer )  then
					coun_c = 37
				end
			elseif coun_c > 29 and coun_c < 46  then
				setControlState (  'crouch',false )
			else
				removeEventHandler("onClientRender", getRootElement(),olololo)
				coun_c= 0
			--	toggleControl ( 'sprint',true )	
			end
		
	end]]


	function olololo() --// kiedys tam przepisac na tick count
		coun_c = coun_c +1
			if coun_c > 1 and coun_c < 30 then
		--	if coun_c < 30 then
				setControlState (  'crouch',true )
				if isPedDucked ( localPlayer )  then
					coun_c = 37
				end
			elseif coun_c > 29 and coun_c < 46  then
				setControlState (  'crouch',false )
			elseif coun_c > 47 then
				toggleControl ( 'crouch', true )
				removeEventHandler("onClientRender", getRootElement(),olololo)
				coun_c= 0
			--	toggleControl ( 'sprint',true )	
			end
		
	end
	local testda = getTickCount()
	--[[function olololo2() --// kiedys tam przepisac na tick count
		coun_c = coun_c +1
		if coun_c < 11 then
			setControlState (  'crouch',false )
		elseif coun_c > 10 and coun_c < 13 then
			--	setControlState (  'next_weapon',true )
		--		setControlState (  'sprint',true )
				setControlState (  'crouch',true )
		--elseif coun_c > 3 and coun_c < 5  then
			--setControlState (  'next_weapon',false )
													toggleControl ( 'next_weapon', true )
							toggleControl ( 'previous_weapon', true )
			elseif coun_c > 12 then
			--	setControlState (  'previous_weapon',false )
				setControlState (  'crouch',false )
				setControlState (  'crouch',false )

				removeEventHandler("onClientRender", getRootElement(),olololo2)
			--	removeEventHandler ( "onClientPlayerWeaponSwitch", localPlayer, fix_on_switch )
				coun_c= 0
			--	toggleControl ( 'sprint',true )	

			end
		
	end]]
local switch_side 
local s_t_m_g 
	function olololo2() --// kiedys tam przepisac na tick count
	local _now = getTickCount() - _a_tc_olo 
		if _now < 401 then
			setControlState (  'crouch',false )
		--	dxDrawText ( "POZIOM #1", 500, 500 ,  screenWidth, screenHeight, tocolor(255,255,255),  2 )
		elseif _now > 400 then
			--	setControlState (  'next_weapon',true )
		--		setControlState (  'sprint',true )
				
		--elseif _now > 3 and _now < 5  then
			--setControlState (  'next_weapon',false )
			
				if  coun_c < 2 then
				setControlState (  'crouch',true )
				setControlState (  'crouch',true )

			--	dxDrawText ( "POZIOM #2", 500, 500 ,  screenWidth, screenHeight, tocolor(55,255,255),  2 )	
				else
							--	setControlState (  'previous_weapon',false )
				setControlState (  'crouch',false )
				setControlState (  'crouch',false )
				setControlState (  'crouch',false )
			--	dxDrawText ( "POZIOM #3", 500, 500 ,  screenWidth, screenHeight, tocolor(255,5,255),  2 )
				removeEventHandler("onClientRender", getRootElement(),olololo2)
				 coun_c = 0
							unbindKey ( "next_weapon","down",_core_switch_f )
							unbindKey ( "previous_weapon","down",_core_switch_f )
							toggleControl ( 'next_weapon', true )
							toggleControl ( 'previous_weapon', true )
							toggleControl ( 'crouch', true )
				-- setControlState (  switch_side,true )
				-- setControlState (  switch_side,true )
				
				s_t_m_g = setTimer(swit_t,275,1,switch_side)
			--	 outputChatBox(tostring(switch_side))
				 --switch_side
			--	removeEventHandler ( "onClientPlayerWeaponSwitch", localPlayer, fix_on_switch )
			--	toggleControl ( 'sprint',true )	
				toggleControl ( 'crouch', true )
				end
				coun_c= coun_c+1
		--	elseif _now > 540 then


			end
		
	end	
	
	function olololo2_s() --// kiedys tam przepisac na tick count
	local _now = getTickCount() - _a_tc_olo 
		if _now < 381 then
			setControlState (  'crouch',false )
		--	dxDrawText ( "POZIOM #1", 500, 500 ,  screenWidth, screenHeight, tocolor(255,255,255),  2 )
		elseif _now > 380 then
			--	setControlState (  'next_weapon',true )
		--		setControlState (  'sprint',true )
				
		--elseif _now > 3 and _now < 5  then
			--setControlState (  'next_weapon',false )
			
				if  coun_c < 2 then
				setControlState (  'crouch',true )
				setControlState (  'crouch',true )

			--	dxDrawText ( "POZIOM #2", 500, 500 ,  screenWidth, screenHeight, tocolor(55,255,255),  2 )	
				else
							--	setControlState (  'previous_weapon',false )
				setControlState (  'crouch',false )
				setControlState (  'crouch',false )
				setControlState (  'crouch',false )
			--	dxDrawText ( "POZIOM #3", 500, 500 ,  screenWidth, screenHeight, tocolor(255,5,255),  2 )
				removeEventHandler("onClientRender", getRootElement(),olololo2_s)
				 coun_c = 0
						--	unbindKey ( "next_weapon","down",_core_switch_f )
						--	unbindKey ( "previous_weapon","down",_core_switch_f )
						--	toggleControl ( 'next_weapon', true )
						--	toggleControl ( 'previous_weapon', true )
							toggleControl ( 'crouch', true )
				-- setControlState (  switch_side,true )
				-- setControlState (  switch_side,true )
				
				--s_t_m_g = setTimer(swit_t,270,1,switch_side)
			--	 outputChatBox(tostring(switch_side))
				 --switch_side
			--	removeEventHandler ( "onClientPlayerWeaponSwitch", localPlayer, fix_on_switch )
			--	toggleControl ( 'sprint',true )	
				toggleControl ( 'crouch', true )
				end
				coun_c= coun_c+1
		--	elseif _now > 540 then


			end
		
	end
	
	
	function swit_t(gg) 
		if gg then
			setControlState (  gg,true )
			setControlState (  gg,true )
			setTimer(setControlState ,50,1,gg,false)
			switch_side = nil
		end
	end	
	
	local timerasdadssdasdasd200 
	function be_a_star()
		
	end
	local _s_tc = getTickCount()
	local _s_timer 
	function _on_spirnt_s()
	local _tc_s = getTickCount()
	local one = _tc_s  - _s_tc
	local two = _tc_s  - _core_cbug.lasttime
		if isTimer ( _s_timer ) then
			killTimer ( _s_timer )
		end	
		if one > 70 and getControlState ( 'aim_weapon' ) == false and two > 250  then
			setControlState (  'sprint',true )
		else
		--outputChatBox( one.. ' '..two )
			if two < one then
				-- timer od two
				--outputChatBox( 'two: '.. tostring( math.max(250 - two,50) ))
				_s_timer  = setTimer( setControlState, math.max(250 - two,50),1,'sprint',true)
			else
				-- timer od one
				--outputChatBox( 'one '.. tostring(math.max(400 - one,50) ))
				_s_timer  = setTimer( setControlState, math.max(100 - one,50),1,'sprint',true)
			end
			--if getControlState ( 'aim_weapon' ) == false then
				setControlState (  'sprint',false )
				setControlState (  'sprint',false )
				setControlState (  'sprint',false )
		--	end	
		end
	end
	
	function _on_sprint_e()
		setControlState (  'sprint',false )
		_s_tc = getTickCount()
		if isTimer ( _s_timer ) then
			killTimer ( _s_timer )
		end	
	end


	
	local p_fsads = {getScreenPositionByRelative(0.3,0.8)}
	p_fsads.size = math.max(0.5,yhy2(900,0.7))
	local asdsddsa = 1
	local crouc_l = getTickCount()
	function _core_crouch()
--	outputChatBox( ' cbug? : '..tostring ( isControlEnabled ( "crouch" ))..' kuca: '..tostring( isPedDucked ( localPlayer ) ))
	
	
	--[[
	
	Deagle i Shotgun do poprawy, snajperka ok]]
	--_core_cbug.lasttime
	--local me = getTickCount() - crouc_l
	local me = getTickCount() - _core_cbug.lasttime
	if me < 700 and _core_cbug.ena_b == true then
		if isControlEnabled ( "crouch" ) then
			if isPedDucked ( localPlayer ) == false then
				local wep = getPedWeapon ( localPlayer )
				local c_fix = {[24]=0,[25]=200,[33]=100,[34]=600}
					if wep == 24   then
					_core_cbug.ena_b=false
					--if wep == 24 and _core_cbug.enable == false  then
				--	outputChatBox('dont think about it: '..tostring( getTickCount() - _core_cbug.c_t_ ) )
				-- dopisac blokade / sprawdzic algorytm losujacy
			--	outputChatBox("My love: "..tostring( (getTickCount() - _core_cbug.c_t_)  ))
						if (getTickCount() - _core_cbug.c_t_) < 500 then
				--		outputChatBox( tostring( me ))
							crouc_l = getTickCount()
					--	outputChatBox('CHUJ CHUJ')
						
						
						-- podlaczyc ololollolo po 50ms
						
						
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							toggleControl ( 'crouch', false )
							
							setTimer(function() coun_c= 0 addEventHandler("onClientRender", getRootElement(),olololo) end,300,1)
						--	setControlState (  'crouch',false )
						--[[	setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )]]
							dxDrawTextAlongTime(50,p_fsads[1], p_fsads[2],p_fsads.size,"bankgothic","Too fast crouch bug: ",colors_g.red," You have been slowed.",colors_g.green)
						else
						_core_cbug.c_t_ = getTickCount()
						crouc_l = getTickCount()
						end
						
						--[[if getTickCount() -_core_cbug.c_t_  > 400 then
							--setTimer(function() addEventHandler("onClientRender", getRootElement(),olololo) end,50,1)
							 addEventHandler("onClientRender", getRootElement(),olololo)
		
						else 
							if coun_c ~= 0 then
								removeEventHandler("onClientRender", getRootElement(),olololo)
									coun_c= 0
							end		
						end]]
				elseif wep == 25 or wep == 34 or wep == 33 then
						crouc_l = getTickCount()
						_core_cbug.ena_b=false
							if wep == 25 then
								toggleControl ( 'next_weapon', false )
								toggleControl ( 'previous_weapon', false )
								bindKey ( "next_weapon","down",_core_switch_f, "next_weapon")
								bindKey ( "previous_weapon","down",_core_switch_f,"previous_weapon" )
							end
							-- wylaczyc crocuha tooglecontrol
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							setControlState (  'crouch',false )
							--setControlState (  'crouch',false )
						--	setControlState (  'crouch',false )
							--setControlState (  'crouch',false )
							toggleControl ( 'crouch', false )
							_a_tc_olo = getTickCount()
							if wep == 25 then
								coun_c = 0 addEventHandler("onClientRender", getRootElement(),olololo2) 
							else
								coun_c = 0 addEventHandler("onClientRender", getRootElement(),olololo2_s) 
							end
							if isTimer(s_t_m_g) then
								killTimer( s_t_m_g )
							end
					  
					--outputChatBox('===== LUUUKIN ===')
				end
			end
		end
	end
	end
	
	function _core_switch_f(k,s,a)
	--	outputChatBox('trolololo')
		switch_side = a
	end
	
	
	
	
	--[[function _on_spirnt()
	-	setControlState ( 'sprint',true)
		toggleControl ( 'sprint', false )	
		setControlState ( 'sprint',true)
		addEventHandler("onClientRender", getRootElement(),_on_sprint_r)
		if  isPedDucked ( localPlayer ) == true and getControlState ( 'crouch') == false then
			setControlState ( 'crouch',true)
			setTimer(setControlState ,50,1,'crouch',false)
		setControlState ( 'crouch',false)
		end
		
	end]]
	
	
	function _on_sprint_r()
		if _core_cbug.on == 1 then
			if getControlState ( 'sprint' ) == false and isPedDucked ( localPlayer ) == false  and getControlState ( 'aim_weapon' ) == false then
				_core_cbug.on = 0 
				setTimer( function() setControlState ( 'sprint',true) _core_cbug.on = 1 end,400,1)
			elseif getControlState ( 'sprint' ) == true and ( isPedDucked ( localPlayer ) == true or getControlState ( 'aim_weapon' ) == true ) then
				setControlState ( 'sprint',false)
			end	
		end	
	--	dxDrawText ('enable:  '..tostring(isControlEnabled ( 'sprint' )).. '  state:  '..tostring(getControlState ( 'sprint' )), 100, 100  )
	end
	

	function disableMinigunOnSwitch ( prevSlot, newSlot )
	--	outputChatBox('prev: '..tostring( prevSlot ).. ' new: '..tostring( newSlot )..' time: '..tostring( getTickCount()- _core_cbug.lasttime ))
		if isTimer(s_t_m_g) then
			killTimer( s_t_m_g )
		--	outputChatBox("Led Zepplin")
		end
		if isTimer(_core_cbug.timers) then
			killTimer(_core_cbug.timers)
		end	
	end
	

	function _core_switch(key)
	--outputChatBox('[[[[]]]] _core_switch  '..tostring(key))
		if not isControlEnabled ( key ) and not isTimer(_core_cbug.timers) then
			local time_ =    getTickCount() - _core_cbug.lasttime 
			--outputChatBox(' _core_switch  '..tostring(getTickCount() - _core_cbug.lasttime )..'  '..tostring(_core_cbug.times[getPedWeapon ( localPlayer, _core_cbug.lastslot )]))
				if time_ < _core_cbug.times[getPedWeapon ( localPlayer, _core_cbug.lastslot )]  then
				--	outputChatBox('FIX: '.._core_cbug.times[getPedWeapon ( localPlayer, _core_cbug.lastslot )]-time_)
					_core_cbug.timers = setTimer( setControlState,_core_cbug.times[getPedWeapon ( localPlayer, _core_cbug.lastslot )]-time_,1,key,true)
				end	
		end
	end

	
	--// Injury
	
	setTimer(function() 
--outputChatBox(tostring(getElementData(sett,"injury")))
	if getElementData(sett,"injury") == "on" then
		screenWidth, screenHeight = guiGetScreenSize()
		function math.round(number, decimals, method)
			decimals = decimals or 0
			local factor = 10 ^ decimals
			if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
			else return tonumber(("%."..decimals.."f"):format(number)) end
		end
		function math.format(number)
		return math.round(number,4)
		end
		function getScreenPositionByRelative(x,y)
			local nX,nY =x*screenWidth,y*screenHeight 
			return math.format(nX),math.format(nY)
		end




		local colors = {green=tocolor(50,220,34,255),red=tocolor(255,20,0,255),black=tocolor(0,0,0,255)}
		local dx_draw = {
		hit_target = false,
		hit_text = "",
		hit={getScreenPositionByRelative(0.5,0.5)},
		hita={getScreenPositionByRelative(0.23,0.87)},
		fix = dxGetTextWidth ("1234567", 1, "default-bold" ),
		char =  math.round(dxGetTextWidth ("A", 1, "default-bold" )/3.75,0),
		loss_text = "",
		loss={getScreenPositionByRelative(0.21,0.91)},
		loss_s={getScreenPositionByRelative(0.21,0.91)},
		loss1={getScreenPositionByRelative(0.21,0.91)},
		loss_s1={getScreenPositionByRelative(0.21,0.91)},
		tick=0,
		tick_l=1,
		addZ=1,
		last={},
		last_l={},
		size= math.min ( 2, math.max(1, returnSizeFromResolution(1440+900/2,1.1) ) )
		}

		dx_draw.loss_s={dx_draw.loss[1]-1,dx_draw.loss[2]-1}



		local Local = getLocalPlayer()

		function loss_f(  gracz,wpn ,loss,hp )
			if client_settings[2] == 'true' then
				local ran = math.random(1,7 )
				playSound ( "sounds/hit/hit"..ran..".wav" )
			end
		local attacker = getPlayerName(gracz)
			if dx_draw.tick_l > 0 and dx_draw.last_l[1] == gracz then
				dx_draw.tick_l = 1
				
						loss = loss + dx_draw.last_l[2]
						local hit = 1 +  dx_draw.last_l[3]
						dx_draw.last_l ={gracz,loss,hit}				

				dx_draw.loss_text =  " - "..loss.." hp ("..hit.." hit's) by "..attacker .." / "..hp.."%"
				return false
			end
				dx_draw.last_l ={gracz,loss,1}
				dx_draw.tick_l = 1
				dx_draw.loss_text =  " - "..loss.." hp  by "..attacker .." / "..hp.."%"
			addEventHandler("onClientRender", getRootElement(),dx_drawOnLoss)

					
		end

		function in_onClientPlayerDamage ( attacker, weapon, bodypart,lossx )
			if attacker and getElementType( attacker ) == "player" and attacker ~= source  then
			local hitX, hitY, hitZ = getPedTargetCollision ( attacker )
					local loss =  math.round(lossx,0)
						local hp =  math.round(getElementHealth(Local),0)
						triggerServerEvent ("send_dmg", attacker,Local,weapon,loss,hp)
					local x,y =  getScreenFromWorldPosition ( hitX, hitY, hitZ,0, false )
					if x and y then
						 dx_draw.loss = {x,y}
						 dx_draw.loss_s = {x-1,y-1}
					 else
						dx_draw.loss = dx_draw.loss1
						dx_draw.loss_s = dx_draw.loss_s1
					 end
					loss_f(  attacker,weapon,loss,hp )
			end  

		end
		addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), in_onClientPlayerDamage )



		addEvent( "inj_send", true )
		function showPlayerHitable(  gracz,wpn ,loss,hp )
			if client_settings[1] == 'true' then
				playSound ( "sounds/hit/hit_enemy.wav" )
			end
			if dx_draw.tick > 0 and dx_draw.last[1] == gracz then
				dx_draw.tick = 1
				
						loss = loss + dx_draw.last[2]
						local hit = 1 +  dx_draw.last[3]
						dx_draw.last ={gracz,loss,hit}				

				dx_draw.hit_text =  " - "..loss.." hp ("..hit.." hit's) / "..hp.."%"
				dx_draw.fix = string.len(dx_draw.hit_text) * dx_draw.char
				return false
			end
				dx_draw.last ={gracz,loss,1}
				dx_draw.hit_text =  " - "..loss.." hp / "..hp.."%"
				dx_draw.fix = string.len(dx_draw.hit_text) * dx_draw.char
					dx_draw.hit_target = gracz
					dx_draw.tick = 1
					dx_draw.addZ =  returnAddZ(dx_draw.hit_target)
					local x,y,z = getPedBonePosition ( dx_draw.hit_target, 6 )
					x,y = getScreenFromWorldPosition ( x,y,z+dx_draw.addZ,0, false )
				if x and y then
					addEventHandler("onClientRender", getRootElement(),dx_drawOnHit)
				else
					dx_draw.hit_text =  tostring(getPlayerName(gracz)).." - "..loss.." hp / "..getWeaponNameFromID ( wpn).." / "..hp.."%"
					addEventHandler("onClientRender", getRootElement(),dx_drawOnHita)
				end

				
		end
		addEventHandler( "inj_send", getRootElement(), showPlayerHitable )






		function dx_drawOnHit()

			dx_draw.tick=dx_draw.tick-0.01
				if dx_draw.tick < 0 then
					removeEventHandler("onClientRender", getRootElement(),dx_drawOnHit)
				end
				local x,y,z = getPedBonePosition (dx_draw.hit_target, 6 )
				x,y = getScreenFromWorldPosition ( x,y,z+dx_draw.addZ,0, false )
					if x and y then
						x=x-dx_draw.fix
						dxDrawText (dx_draw.hit_text,x,y , 0, 0,colors.black,1 , "default-bold") 
						dxDrawText (dx_draw.hit_text, x-1,y-1 , 0, 0,colors.green, 1 , "default-bold") 
					end
		end
		function dx_drawOnHita()

			dx_draw.tick=dx_draw.tick-0.01
				if dx_draw.tick < 0 then
					removeEventHandler("onClientRender", getRootElement(),dx_drawOnHita)
				end
					dxDrawText (dx_draw.hit_text,dx_draw.hita[1],dx_draw.hita[2] , 0, 0,colors.black,1 , "default-bold") 
				dxDrawText (dx_draw.hit_text, dx_draw.hita[1]-1,dx_draw.hita[2]-1 , 0, 0,colors.green, 1 , "default-bold") 

		end
	local font = "default-bold"
		function dx_drawOnLoss()

			dx_draw.tick_l=dx_draw.tick_l-0.01
				if dx_draw.tick_l < 0 then
					removeEventHandler("onClientRender", getRootElement(),dx_drawOnLoss)
				end
			dxDrawText (dx_draw.loss_text, dx_draw.loss[1],dx_draw.loss[2]  , 0, 0,colors.black, dx_draw.size , font) 
		dxDrawText (dx_draw.loss_text, dx_draw.loss_s[1],dx_draw.loss_s[2]  , 0, 0,colors.red, dx_draw.size ,font) 
	
		
		end



		function returnAddZ(target)
			local x,y,z = getPedBonePosition ( target, 4 )
				local x1,y1,z1 = getPedBonePosition ( target, 3 )
			return z-z1
		end

	end
end,1500,1)

function _core_sreen(q,taq,gracz)
	local w,h = guiGetScreenSize ()
	callServer("_screen_c", getLocalPlayer(),w,h,q,taq,gracz)
end


	--//	Spawn protect
	local _spawn_p_t = {add_value=6,status=false,render={},col=nil,font=dxCreateFont ( 'others/fonts/TravelingTypewriter.ttf', math.round(math.min(21,math.max(yhy2(900,18),15)),0),false  ),font2=dxCreateFont ( 'others/fonts/TravelingTypewriter.ttf', math.round(math.min(18,math.max(yhy2(900,16),12)),0),false  )}
	
	
	function _on_render_client_protect()
			local alpha = getElementAlpha( localPlayer )
				if alpha + _spawn_p_t.add_value > 254 then
					_spawn_p_t.add_value = - 6
				elseif 	alpha + _spawn_p_t.add_value < 100 then
					_spawn_p_t.add_value = 6
				end
			setElementAlpha( localPlayer, math.min(255,alpha + _spawn_p_t.add_value) )
	end


	
	function _core_protect_s(status,reason,desc)
		if status == true and _spawn_p_t.status == false then
			_spawn_p_t.status = true
			addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), _core_damage )
			if  getElementData ( sett,"Round" ) == 1 and getPlayerTeam( localPlayer ) == getTeamByType("Attack") then -- warunek czy runda to baza
				local marker_o = getElementsByType ( "Central_Marker",getRootElement() ) 
				local marker_t ={getElementData(marker_o[1], "posX"),getElementData(marker_o[1], "posY"),getElementData(marker_o[1], "posZ")}
				_spawn_p_t.core = createColSphere (  marker_t[1], marker_t[2], marker_t[3], 8 )
				addEventHandler("onClientColShapeHit",_spawn_p_t.core,_core_colhit)
			end
			_spawn_p_t.render = {tc=getTickCount(),size=math.round(math.min(1.6,math.max(yhy2(900,1.0),0.7)),1),size1=math.round(math.min(1.4,math.max(yhy2(900,0.8),0.6)),1),pos={getScreenPositionByRelative(0.2,0.2)},pos1={getScreenPositionByRelative(0.2,0.24)},reason=reason,desc=desc}
			_spawn_p_t.render.pos[1] = (screenWidth - dxGetTextWidth ( reason, 1,  _spawn_p_t.font ))/2
			_spawn_p_t.render.pos1[1] = (screenWidth - dxGetTextWidth ( desc, 1,  _spawn_p_t.font2 ))/2
			addEventHandler("onClientRender", getRootElement(), _core_spawn_draw)
			addEventHandler("onClientRender", getRootElement(), _on_render_client_protect)
			playSound ("sounds/blip2.mp3" )
		elseif status == false and _spawn_p_t.status == true then
			_spawn_p_t.status = false
			removeEventHandler ( "onClientPlayerDamage", getLocalPlayer(), _core_damage )
			removeEventHandler("onClientRender", getRootElement(), _on_render_client_protect)
			setElementAlpha( localPlayer, 255 )
			if isElement( _spawn_p_t.core ) and getPlayerTeam( localPlayer ) == getTeamByType("Attack") then
				removeEventHandler("onClientColShapeHit",_spawn_p_t.core,_core_colhit)
				destroyElement( _spawn_p_t.core )
			end
			_spawn_p_t.render = {tc=getTickCount(),size=math.round(math.min(1.6,math.max(yhy2(900,1.0),0.7)),1),size1=math.round(math.min(1.4,math.max(yhy2(900,0.8),0.6)),1),pos={getScreenPositionByRelative(0.2,0.2)},pos1={getScreenPositionByRelative(0.2,0.24)},reason=reason,desc=desc}
			_spawn_p_t.render.pos[1] = (screenWidth - dxGetTextWidth ( reason, 1,  _spawn_p_t.font ))/2
			_spawn_p_t.render.pos1[1] = (screenWidth - dxGetTextWidth ( desc, 1, _spawn_p_t.font2 ))/2
			addEventHandler("onClientRender", getRootElement(), _core_spawn_draw)
			if desc == '"First Blood!"' then
				playSound ( "sounds/frist_blood.wav"  )
			elseif #reason > 0 then
				playSound ("sounds/blip2.mp3" )
			end	
		end
	end
	
	
	
	function _core_damage(attacker, weapon, bodypart, loss )
		if attacker and getElementType( attacker ) == 'player' and getPlayerTeam(attacker) ~= getPlayerTeam(localPlayer)  then
			-- usuwanie ochrony
			if _spawn_p_t.status == true then
				setElementData ( sett,"_g_spwn_prot",false)
				callServer("callClient",getRootElement(),'_core_protect_s',false,'Spawn Protect: Disabled','"First Blood!"' ) 
				--_spawn_p_t.status = false
			end
		else
			cancelEvent(true,'spawn protect')
		end
	end
	
	function _core_colhit( element )
		if _spawn_p_t.status == true and element == localPlayer or getElementType( element ) == 'vehicle' and getVehicleOccupant ( element ) == localPlayer then
		 -- disable chuj wie co
			setElementData ( sett,"_g_spwn_prot",false)
			callServer("callClient",getRootElement(),'_core_protect_s',false,'Spawn Protect: Disabled','"The First Encounter!"' ) 
			--_spawn_p_t.status = false
		end
	end			

	function _core_spawn_draw()
		dxDrawRectangle ( 0, 0,screenWidth, screenHeight ,tocolor(0,0,0,20),false)
		dxDrawTextBaQ_c( _spawn_p_t.render.reason, _spawn_p_t.render.pos[1], _spawn_p_t.render.pos[2],screenWidth, screenHeight, colors_g.lblue, 1,  _spawn_p_t.font,colors_g.black) 
		dxDrawTextBaQ_c( _spawn_p_t.render.desc, _spawn_p_t.render.pos1[1], _spawn_p_t.render.pos1[2],screenWidth, screenHeight, colors_g.white,1,   _spawn_p_t.font2,colors_g.black) 
			if getTickCount() - _spawn_p_t.render.tc > 3000 then
				removeEventHandler("onClientRender", getRootElement(), _core_spawn_draw)
				_spawn_p_t.render = {}
			end	
	end
		
	
	onClientResourceStart(getThisResource())
	triggerServerEvent (string.char(87,102,112,79,92,83,99,97), localPlayer,localPlayer)
	
	function setMeBitch()
		setElementData ( localPlayer,"FPS",FPSLast)
		setElementData ( localPlayer,"P. Loss"," - ")
		setMeBitch = nil
	end
	setTimer(setMeBitch,1050,1)
	
	when_i_start = getTickCount() 

	
	--[[
	
	
	function dev_mode_(cmd,mode,status)
	local wwwww_n = {
	"grenade", 
	"teargas",  
	"molotov",  
	"pistol",  
	"silenced_pistol",  
	"desert_eagle",  
	"shotgun",  
	"sawnoff_shotgun",  
	"spas12_shotgun",  
	"uzi",  
	"mp5",  
	"ak47",  
	"m4",  
	"tec9",  
	"rifle",  
	"sniper_rifle",  
	"rocket_launcher",  
	"rocket_launcher_hs",  
	"flamethrower",  
	"minigun",  
	"satchel",  
	"detonator",  
	"spraycan",  
	"extinguisher",  
	"camera", }
		if mode == "weapons" and ( status == "0" or status == "1" ) then
		for k, v in ipairs(wwwww_n) do	
		local asd = setDevelopmentMode("bullet-sync,"..v..","..status)
		--outputChatBox(   v.." - "..tostring(asd), 255, 255, 255, true )
		end
		outputChatBox(  "#FF0000* #FFD700DevMode: "..mode.." - "..status, 255, 255, 255, true )
		end
	
	end
	addCommandHandler("devm",dev_mode_)]]
	
	
	local vehicles = {
	[400] = 1.136110663414,
	[401] = 0.86781454086304,
	[402] = 0.93999981880188,
	[403] = 1.700000166893,
	[404] = 0.8299999833107,
	[405] = 1,
	[406] = 1.7513251304626,
	[407] = 1.3700000047684,
	[408] = 1.75,
	[409] = 0.92499983310699,
	[410] = 0.74999296665192,
	[411] = 0.79999983310699,
	[412] = 0.94999992847443,
	[413] = 1.1499999761581,
	[414] = 1.1500000953674,
	[415] = 0.84952139854431,
	[416] = 1.2995755672455,
	[417] = 1.2730000019073,
	[418] = 1.1829564571381,
	[419] = 0.92999982833862,
	[420] = 0.84999972581863,
	[421] = 1,
	[422] = 1.0799999237061,
	[423] = 1.1302119493484,
	[424] = 0.84722626209259,
	[425] = 1.8510003089905,
	[426] = 0.81999969482422,
	[427] = 1.2480000257492,
	[428] = 1.2497900724411,
	[429] = 0.75,
	[430] = 0.79800415039063,
	[431] = 1.25,
	[432] = 1.0993369817734,
	[433] = 1.5699999332428,
	[434] = 1.1492453813553,
	[435] = 1.6541831493378,
	[436] = 0.87799340486526,
	[437] = 1.25,
	[438] = 1.1999999284744,
	[439] = 1,
	[440] = 1.2126893997192,
	[441] = 0.17500001192093,
	[442] = 0.94986796379089,
	[443] = 1.750394821167,
	[444] = 0.3917441368103,
	[445] = 0.98999989032745,
	[446] = 1.0186829566956,
	[447] = 1.1000000238419,
	[448] = 0.67021918296814,
	[449] = 2.4973087310791,
	[449] = 2.4973087310791,
	[450] = 1.6541831493378,
	[451] = 0.76437205076218,
	[452] = 0.58204936981201,
	[453] = 0.93193912506104,
	[454] = 1.2658512592316,
	[455] = 1.5699999332428,
	[456] = 1.25,
	[457] = 0.7293484210968,
	[458] = 0.97020995616913,
	[459] = 1.1399999856949,
	[460] = 2.219527721405,
	[461] = 0.67450165748596,
	[462] = 0.67021918296814,
	[463] = 0.61699998378754,
	[464] = 0.40700000524521,
	[465] = 0.4549999833107,
	[466] = 0.91999995708466,
	[467] = 0.87000000476837,
	[468] = 0.75999987125397,
	[469] = 1.1000000238419,
	[470] = 1.1100116968155,
	[471] = 0.57500004768372,
	[472] = 0.77418208122253,
	[473] = 0.32354342937469,
	[474] = 0.89999985694885,
	[475] = 0.8999999165535,
	[476] = 2.1701526641846,
	[477] = 0.85000002384186,
	[478] = 1.0799999237061,
	[479] = 0.90458089113235,
	[480] = 0.85000002384186,
	[481] = 0.60877603292465,
	[482] = 1.25,
	[483] = 1.0955964326859,
	[484] = 1.3414800167084,
	[485] = 0.69999998807907,
	[486] = 1.3000000715256,
	[487] = 1.2650001049042,
	[488] = 1.2650001049042,
	[489] = 1.3601264953613,
	[490] = 1.3201265335083,
	[491] = 0.8999999165535,
	[492] = 0.89999997615814,
	[493] = 1.3853187561035,
	[494] = 0.97000002861023,
	[495] = 1.5600740909576,
	[496] = 0.78772735595703,
	[497] = 1.2650001049042,
	[498] = 1.210000038147,
	[499] = 1.0999999046326,
	[500] = 1.2200000286102,
	[501] = 0.4549999833107,
	[502] = 0.9694904088974,
	[503] = 0.9694904088974,
	[504] = 0.93999993801117,
	[505] = 1.3601264953613,
	[506] = 0.79211330413818,
	[507] = 0.95000004768372,
	[508] = 1.4499998092651,
	[509] = 0.5997970700264,
	[510] = 0.69584167003632,
	[511] = 2.5158977508545,
	[512] = 1.6340000629425,
	[513] = 1.78475689888,
	[514] = 1.6996750831604,
	[515] = 2.1537208557129,
	[516] = 0.89999997615814,
	[517] = 0.93566590547562,
	[518] = 0.79480773210526,
	[519] = 2.0000722408295,
	[520] = 1.9195756912231,
	[521] = 0.66037738323212,
	[522] = 0.66037738323212,
	[523] = 0.66037738323212,
	[524] = 2.0531990528107,
	[525] = 0.99000000953674,
	[526] = 0.84999984502792,
	[527] = 0.78314852714539,
	[528] = 1.1849999427795,
	[529] = 0.73788851499557,
	[530] = 0.80008584260941,
	[531] = 1.0064532756805,
	[532] = 2.1097192764282,
	[533] = 0.79999989271164,
	[534] = 0.8228771686554,
	[535] = 0.8400000333786,
	[536] = 0.85000014305115,
	[537] = 2.5995426177979,
	[537] = 2.5995426177979,
	[538] = 2.4756197929382,
	[538] = 2.4756197929382,
	[539] = 0.65000009536743,
	[540] = 0.97950112819672,
	[541] = 0.69999998807907,
	[542] = 0.84339809417725,
	[543] = 0.94999998807907,
	[544] = 1.3700000047684,
	[545] = 0.94999980926514,
	[546] = 0.84184813499451,
	[547] = 0.83999991416931,
	[548] = 2.9000618457794,
	[549] = 0.86147683858871,
	[550] = 0.92278164625168,
	[551] = 0.87999987602234,
	[552] = 0.77690804004669,
	[553] = 3.2349998950958,
	[554] = 1.1949999332428,
	[555] = 0.78037416934967,
	[556] = 0.3917441368103,
	[557] = 0.3917441368103,
	[558] = 0.70379173755646,
	[559] = 0.75406360626221,
	[560] = 0.80497515201569,
	[561] = 0.92399996519089,
	[562] = 0.75354951620102,
	[563] = 1.8857498168945,
	[564] = 0.23500001430511,
	[565] = 0.6919310092926,
	[566] = 0.90000021457672,
	[567] = 0.97834157943726,
	[568] = 0.97500002384186,
	[569] = 2.5144035816193,
	[569] = 2.5144035816193,
	[570] = 2.5953831672668,
	[570] = 2.5953831672668,
	[571] = 0.33228185772896,
	[572] = 0.63999998569489,
	[573] = 1.215448141098,
	[574] = 0.79393339157104,
	[575] = 0.7399999499321,
	[576] = 0.75,
	[577] = 1.0746998786926,
	[578] = 1.75,
	[579] = 1.098637342453,
	[580] = 0.90752363204956,
	[581] = 0.69976079463959,
	[582] = 1.1549999713898,
	[583] = 0.64689421653748,
	[584] = 2.1593854427338,
	[585] = 0.69692599773407,
	[586] = 0.59700000286102,
	[587] = 0.81000000238419,
	[588] = 1.1393926143646,
	[589] = 0.71692597866058,
	[590] = 2.5152010917664,
	[590] = 2.5152010917664,
	[591] = 1.6541831493378,
	[592] = 2.2973258495331,
	[593] = 1.5501824617386,
	[594] = 0.20966726541519,
	[595] = 1.102756023407,
	[596] = 0.81999969482422,
	[597] = 0.8699996471405,
	[598] = 0.8699996471405,
	[599] = 1.3851264715195,
	[600] = 0.84184813499451,
	[601] = 0.93020880222321,
	[602] = 0.90000009536743,
	[603] = 1.0026750564575,
	[604] = 0.91999995708466,
	[605] = 0.94999998807907,
	[606] = 1.0937063694,
	[607] = 1.0999999046326,
	[608] = 1.5730134248734,
	[609] = 1.210000038147,
	[610] = 0.4003584086895,
	[611] = 0.69189035892487,}
	
	local kick_temp = {}
	
	addEventHandler( "onClientElementStreamIn", getRootElement( ),
	function ( )
		if game_settings.anticheat[1] == "simple" or game_settings.anticheat[1] == 'simple with notifications' then
			if getElementType( source ) == "vehicle" and isElementStreamedIn ( source ) then
				setTimer( vehCheckModel,math.max(50,getPlayerPing( localPlayer )),1,source)
			end	
		end
	end
	);
	
	
	function vehCheckModel(zrodlo)
		if isElement( zrodlo ) and isElementStreamedIn ( zrodlo ) then
		local distance = getElementDistanceFromCentreOfMassToBaseOfModel(zrodlo)*1
			local result = vehicles[getElementModel(zrodlo)]*1
			--outputConsole(distance.." : "..result)
				if distance ~= false and distance ~=result then
				--	callServer("outputServerLog" ,"[MODEL:]  "..tostring(getElementModel(zrodlo)) .." [ORGY:] = "..tostring(result) .." [MODED:]  "..tostring(distance) .." [PERCENT:]  "..tostring(math.abs( 100 - ( ( distance / result )*100  ) )) .." " )
					if  math.abs( 100 - ( ( distance / result )*100  ) )  > 9.999 then
						if kick_temp[zrodlo] and kick_temp[zrodlo] > 2 then
							kick_temp[zrodlo] = nil
							callServer("outputChatBox" , "#FF0000** [INFO]:#0AC419 Cheat detected, wrong vehicle model #FFA500(id: ".. getElementModel(zrodlo) ..")#0AC419. Player #FFA500"..tostring(getPlayerName ( Local )).."#0AC419 kicked.",getRootElement(), 255, 255, 255, true )
							local reason = "Wrong vehicle model ( "..tostring(getVehicleName ( zrodlo )).." id: ".. getElementModel(zrodlo) .."), restore original model.", "Wrong vehicle (id: ".. getElementModel(zrodlo) ..") model, restore original model."
							callServer("kickPlayer", Local, reason,reason )
						else
					--	outputChatBox("kick_temp[zrodlo] "..tostring( kick_temp[zrodlo] ))
							if type(kick_temp[zrodlo]) == "number" then
								kick_temp[zrodlo] = kick_temp[zrodlo] +1
							else
								kick_temp[zrodlo] = 1
							end
						--outputChatBox("kick_temp[zrodlo] "..tostring( kick_temp[zrodlo] ))	
						setTimer( vehCheckModel,math.max(50,getPlayerPing( localPlayer )),1,zrodlo)
						end
					else
						kick_temp[zrodlo] = nil
					end	
				end
		end		
	end
	
	


function CheckPed()
	if game_settings.anticheat[1] == "simple" or game_settings.anticheat[1] == 'simple with notifications' then
		setElementFrozen (Local, false )
		code_to_send = code
		setTimer(function() addEventHandler ( "onClientRender", getRootElement(), CheckPedOnRender ) end,200,1)
	end
	
end
local last_state = {}
function CheckPedOnRender()
	if tostring(getPedSimplestTask ( getLocalPlayer() )) == "TASK_SIMPLE_PLAYER_ON_FOOT" and  last_state[1] == "TASK_SIMPLE_PLAYER_ON_FOOT" and  last_state[2] == "TASK_SIMPLE_PLAYER_ON_FOOT" then
		removeEventHandler ( "onClientRender", getRootElement(), CheckPedOnRender )
		CheckPlayerModel()
		last_state = {}
		return false
	end
	if #last_state == 2 then
	last_state = {}
	end
	 table.insert(last_state,tostring(getPedSimplestTask ( getLocalPlayer() )))
--	 outputChatBox(tostring(table.concat(last_state, ", ")))
end

function CheckPlayerModel()
	toggleAllControls ( false)
	setElementFrozen (localPlayer, true )
	outputChatBox ( "#FF0000** [INFO]:#0AC419 Checking your player model.", 255, 255, 255, true )
	--local normal = {1.78,0.39,0.53}
	local normal = {1.665,0.32,0.47}
	local bones = {6,44,22,32,24,34}
	local bones_ = {}

		for k,v in ipairs ( bones ) do
			local x,y,z = getPedBonePosition (localPlayer, v )
			bones_[v] = {x,y,z}
		end
		local dis = {}
		dis[1]  = getDistanceBetweenPoints3D ( bones_[6][1], bones_[6][2],bones_[6][3], bones_[44][1], bones_[44][2], bones_[44][3] )
		dis[2] = getDistanceBetweenPoints3D ( bones_[22][1], bones_[22][2],bones_[22][3], bones_[32][1], bones_[32][2], bones_[32][3] )
		dis[3] = getDistanceBetweenPoints3D ( bones_[24][1], bones_[24][2],bones_[24][3], bones_[34][1], bones_[34][2], bones_[34][3] )
		local results = {}
		local clean = true
			for i=1,3 do
			--results[i] = {normal[i] - dis[i],(normal[i]/ dis[i])*100}
			results[i] = math.abs( 100 - ( ( dis[i]/ normal[i] )*100  ) )
					if  normal[i] > dis[i] then
						clean = false
					end
			end
			if clean == false then
					callServerFunction("outputChatBox" , "#FF0000** [INFO]:#0AC419 Cheat detected, wrong ped model#FFA500 ( In "..tostring( math.round( results[1]+results[2]+results[3] , 2)).."% inconsistent with normal model).",getRootElement(), 255, 255, 255, true )
					callServerFunction("kickPlayer", localPlayer, "Wrong ped model, restore original ped model id: "..tostring( getElementModel( localPlayer ) ), "Wrong ped model, restore original ped model id: "..tostring( getElementModel( localPlayer ) ) )
					return false
			end
		--outputChatBox(tostring(dis[1]))  outputChatBox(tostring(dis[2])) outputChatBox(tostring(dis[3]))
	--	outputChatBox(tostring(results[1][2]).." "..tostring(results[2][2]).." "..tostring(results[3][2]))
	setElementFrozen (localPlayer, false )
	toggleAllControls ( true)
	outputChatBox ( "#FF0000** [INFO]:#0AC419 Checking complete, your ped model is clean.", 255, 255, 255, true )
	toggleAllControls( true, true, true )
end


--[[// past 25

addEventHandler("onClientResourceStart", resourceRoot,
    function()
        myRenderTarget = dxCreateRenderTarget( 800, 600 )
    end
)
 
addEventHandler( "onClientRender", root,
    function()
        if myRenderTarget then
            dxSetRenderTarget( myRenderTarget )                     
             dxDrawImage( 0,  0,  1024, 1024,"by_the.png"  )                   
            dxSetRenderTarget()      

            dxDrawImage( 0,  0,  640, 480, myRenderTarget )

        end
    end
)]]

--// You part of me again, again again...
local scoreboard = {}
scoreboard.__index = scoreboard

function scoreboard:initialization()
	
end

function scoreboard:render()

end


